I've found that Html.BeginForm()
automatically populates the routeValueDictionary with the RawUrl (ie. QueryStringParamters). However I need to specify an HtmlAttribute so I need to use the override...
public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes)
When I do the QueryString values are NOT automatically added to the RouteValueDictionary. How can I accomplish this?
Here is my best attempt but it doesn't seem to be working.
<% 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" }))
{%> ...
My Controller Action looks like this...
[HttpPost]
public ActionResult Login(Login member, string returnUrl)
{ ...
But the value of "returnUrl" which is part of the QueryString is always NULL unless I use the default parameterless Html.BeginForm() in my View.
Thanks, Justin
returnUrl
in your route value dictionary, or you have? – Thibaut<form>
tag generated by your code look like? The reason I ask is because in the case that works you might be POSTing to a URL like "mysite.com?returnUrl=foobar" – Harpole