I have an MVC3 view with a form and i want to pass in a parameter via query string. Heres my form
@using (Html.BeginForm("LogOn", "Account", new { db = @Request.QueryString["db"] }, FormMethod.Post))
Heres my Controller
[HttpPost]
public ActionResult LogOn(LogOnModel model,string db)
When I click my Login button, and step through the code, the param db is null. Im passing it in like this:
http://localhost:64632/?db=someValue
My route looks like this:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{db}", // URL with parameters
new { controller = "Account", action = "LogOn", db = UrlParameter.Optional } // Parameter defaults
);
What am i doing wrong?
dbas a property in your Model, set it on load of that page (it must be set in the query string somewhere), then put it in a hidden field, that way when you submit the form you have the value. Default MVC model binding FTW :)@Request.QueryString["db"]in the view. Did you check whether that value was set correctly?