I am having problems with the default default binding naming assignment when there is a child property. For instance:
I have a ViewModel that looks something like this:
public class UserViewModel { public User BusinessObject { get; set; } }
The My User class has the NetworkLogin property.
My View has something like this: <%: Html.LabelFor (model => model.BusinessObject.NetworkLogin)%> <%: Html.TextBoxFor (model => model.BusinessObject.NetworkLogin)%> Autocomplete
And my controller, what I would like to do,
[HttpGet] public ActionResult UserIndex(string networkLogin) { }
Problem: The input parameter "networkLogin" is always zero. This makes sense because the actual parameter in the html element is name = "BusinessObject.NetworkLogin" and id = "BusinessObject_NetworkLogin". However, I do not know which parameter name I should use in my action method. I tried "businessObject_NetworkLogin" and it does not work either.
However, I have this workaround that really works, but I don't like it. I add this to my ViewModel:
public string NetworkLogin { get { if (BusinessObject == null) BusinessObject = new User(); return BusinessObject.NetworkLogin; } set { if (BusinessObject == null) BusinessObject = new User(); BusinessObject.NetworkLogin = value; } }
And now my browse page is talking about this. <%: Html.TextBoxFor (model => model.NetworkLogin)%>
Can someone tell me what the proper naming convention is for binding the model by default, so that I don't need to use the above workaround?
Thanks!
source share