I have a strongly typed view (IEnumerable<Client>) and I need to post a client to action.
Using:
[HttpPost]
public ActionResult Index(Client client)
When I use @Html.TextBox("Client.Name") and post it, in my action I receive a client object with all properties null.
When I use @Html.TextBox("Name") and post it, in my action I receive a null.
How can I do this?
Well… I reopen my solution and it works with ‘@Html.TextBox(“Name”);’… magic..
In case of Model Binding in ASP.NET MVC you should use the property name of the model without the class name for input elements. So it should be
@Html.TextBox("Name")and not@Html.TextBox("Client.Name").Suppose you have a reference type property(ReferenceTypeProperty) in the Client class and you want to map a property(Member) of that on submitting then you should use
@Html.TextBox("ReferenceTypeProperty.Member").