开发者

MVC 2.0 Post Form to action instead of redirect to action

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开发者_StackOverflow 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 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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜