Here is a strange issue I'm experiencing.
The model:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
The view:
@model Person
<div>
@Html.TextBoxFor(m => m.FirstName)
</div>
<div>
@Html.TextBoxFor(m => m.LastName)
</div>
The action:
public ActionResult Contact(string FirstName, string LastName)
{
// do something with FirstName and LastName passed in
var person = new Person();
person.FirstName = "John";
person.LastName = "Doe";
return View(person);
}
When call the action by:
/Home/Contact?FirstName=Jane&LastName=Smith
In the view it is Jane Smith where John Doe is expected. The view model is clearly the person.
But when the view modified to:
<div>
@Html.TextBox("First Name", Model.FirstName)
</div>
<div>
@Html.TextBox("Last Name", Model.LastName)
</div>
Everything is fine. Why is that? I'm on MVC 5.