Asp.net MVC RETURNURL变量未显示与方法FormMethod.Post在Html.BeginForm [英] Asp.net MVC ReturnUrl variable not showing up with method FormMethod.Post in Html.BeginForm

查看:452
本文介绍了Asp.net MVC RETURNURL变量未显示与方法FormMethod.Post在Html.BeginForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC3的默认模板设置的登录页面的查询字符串'RETURNURL'变量。那么这个页面回发到控制器

The default template in MVC3 sets a 'returnurl' variable in the query string of the logon page. This page then posts back to a controller

@using (Html.BeginForm()) {

这是然后拿起控制器像这样

That is then picked up in the controller like so

[HttpPost]
    public ActionResult LogOn(LogOnModel model, string returnUrl)
    {

我想一个CSS类添加到窗体所以我改变了帮手:

I wanted to add a CSS class to the form so I changed the helper to:

@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @class = "form-horizontal" }))

但是,在查询字符串现在信息没有在控制器获取集合

But now information in the query string isn't getting set in the controller.

我可以隐藏的输入值始终设置在形式retrunurl,但我不知道是否有一个简单的方法。

I could always set a hidden input value to the retrunurl in the form but I didn't know if there was a simpler way.

感谢

推荐答案

您需要使用隐藏域在这种情况下,因为这种超负荷并不preserve其中载有RETURNURL变量原来的查询字符串。或者,如果你不想使用隐藏字段,你可以使用一个查询字符串参数:

You need to use a hidden field in this case because this overload doesn't preserve the original query string which contained the returnurl variable. Or if you don't want to use a hidden field you could use a query string parameter:

@using (Html.BeginForm(null, null, new { returnUrl = Request["returnurl"] }, FormMethod.Post, new { @class = "form-horizontal" }))
{
    ...
}

这篇关于Asp.net MVC RETURNURL变量未显示与方法FormMethod.Post在Html.BeginForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆