Dan*_*net 1 post controller query-string razor asp.net-mvc-3
MVC3中的默认模板在登录页面的查询字符串中设置"returnurl"变量.然后该页面回发给控制器
@using (Html.BeginForm()) {
Run Code Online (Sandbox Code Playgroud)
然后在控制器中拾取它就像这样
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
Run Code Online (Sandbox Code Playgroud)
我想在表单中添加一个CSS类,所以我将帮助器更改为:
@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @class = "form-horizontal" }))
Run Code Online (Sandbox Code Playgroud)
但现在查询字符串中的信息未在控制器中设置.
我总是可以在表单中为retrunurl设置一个隐藏的输入值,但我不知道是否有更简单的方法.
谢谢
在这种情况下,您需要使用隐藏字段,因为此重载不会保留包含returnurl变量的原始查询字符串.或者,如果您不想使用隐藏字段,则可以使用查询字符串参数:
@using (Html.BeginForm(null, null, new { returnUrl = Request["returnurl"] }, FormMethod.Post, new { @class = "form-horizontal" }))
{
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1529 次 |
| 最近记录: |