开发者

ASP.NET MVC 2 Html.actionline : Making it act like a postback, or passing in all current form values into controller action

Hey, is it possible to do either:开发者_如何学C

1) Get the html.actionlink to act like a post back and post all the current form values into a specific controller action? eg.

Index()
{
    Blah
}  
[HttpPost]
Index(FormCollection)
{
    Blah
}

OtherMethod(FormCollection)

2) Or can i pass in all the current values for a form into the parameters for a controller action, besides the obvious having all values as a seperate parameter in the method header? e.g.

OtherMethod(Model m)
{
     Blah
}


By default anchor tags send GET requests only. If you want to send all the values inside a form I would recommend you using a submit button instead of an ActionLink. You could even make it look like a link using image button if this is your concern.

If you really insist on using ActionLink you could have some javascript to subscribe for the click event, submit the form and cancel the redirect. The question is why would you want to go through all this pain when you have the first option.

As far as passing values to a controller action are concerned you can pass them in the request (GET, POST, PUT, DELETE) or route => in this case the model binder will automatically bind them to action parameters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜