ASP.Net MVC Binding Returning Null Values
Given the following markup:
<form method="post" action="/home/index"> Username: <%= Html.TextBox("UserName")%> Password: <%= Html.TextBox("Password")%> <input id="login" type="button" value="Login" /> <input id="Submit1" type="submit" value="submit" /> </form> Can you tell me why model binding does not work when my action is called:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(string UserName, string Password) { //UserName and Password are null! Why? } Edit: Form values ββare published. If I check the Request.Form property, I see that the correct values ββare published.
? Request form {UserName = SDF & Password = SDF} [System.Web.HttpValueCollection]: {UserName = sdf & Password = sdf} base {System.Collections.Specialized.NameObjectCollectionBase}: {UserName = sdf & Password = sdf} AllKeys: {string [2]}
I had a similar problem, and this turned out to be related to the field names.
<form method="post" action="/company/update/3"> Name: <%= Html.TextBox("Company.Name")%> FEIN: <%= Html.TextBox("FEIN")%> <input type="submit" value="submit" /> </form> When sent to:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(int id, Company company) { //Company.FEIN is null! } This is similar to the first post posted in Company.Name.