我发现Html.BeginForm()
自动使用RawUrl(即QueryStringParamters)填充routeValueDictionary。不过,我需要,所以我需要使用override当我这样做的查询字符串值不被自动添加到RouteValueDictionary指定一个HtmlAttribute ...如何使用Html.BeginForm()将QueryString值转换为RouteValueDictionary?
public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes)
。我怎样才能做到这一点?
这是我最好的尝试,但它似乎并没有工作。
<% RouteValueDictionary routeValueDictionary = new RouteValueDictionary(ViewContext.RouteData.Values);
foreach (string key in Request.QueryString.Keys)
{
routeValueDictionary[key] = Request.QueryString[key].ToString();
}
using (Html.BeginForm("Login", "Membership", routeValueDictionary, FormMethod.Post, new { @class = "signin-form" }))
{%> ...
我的控制器动作看起来像这样...
[HttpPost]
public ActionResult Login(Login member, string returnUrl)
{ ...
但“RETURNURL”的值,它是查询字符串的一部分,始终是NULL,除非我用的是默认的无参数Html.BeginForm()在我看来。
感谢, 贾斯汀
你从来没有在你的路线值的字典提到`returnUrl`,或你有? – xandy 2011-01-13 00:44:09
routeValueDictionary变量假设用Request.QueryString中的所有键/值对填充。我可以通过使用新的{returnUrl = Request.QueryString [“ReturnUrl”]}来破解它,但是如果查询字符串中存在多于ReturnUrl的内容。 – Justin 2011-01-13 01:08:12