views:

36

answers:

2

I am using T4MVC to redirect to another action return RedirectToAction(MVC.MyController.MyAction());. In result it is doing get request.

Is there any way to make post request from controller. I want to keep all the same but only make post instead get. I cant find any methods for that. I found one post helper here http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx but i cant pass any values i need using this post helper. I was trying to pass values through TempData but they are not coming when i using this helper. May be some one have any ideas?

The reason i want to do this because when user come from one controller to another and then if user click update or just click enter in browser address bar, page will break.

Should i use session for that reason?

A: 

only way of doing post is by having a form and doing submit on that form, either with a submit button or with javascript, any info you want passed to that action must be in that form and you will find everything posted in FormCollection(hope I spelled it right).

Joakim
+1  A: 

A RedirectToAction will always perform a GET, never a POST (it returns a HTTP 302 to the browser, which will then issue a GET request).

To persist data across the redirect, if it is data that can be easily represented as a string and stored in the query string, then you can just add it to the route values of the redirect. e.g.

return RedirectToAction("Search", new { searchString = "whatever" });

If it is a complex type, then you will need to store it in TempData. A number of other questions on StackOverflow (such as this one) give details on how.

If repeatedly storing to and reading from TempData across your application offends your code-sense, then you can encapsulate this by using the PassParametersDuringRedirect attribute and generic RedirectToAction available in the MvcContrib project. Some details on this technique are available here.

MJ Richardson