I'm having trouble with default model binding naming convention when there is a child property. For example:
I have a ViewModel which looks something like this:
public class UserViewModel
{
public User BusinessObject { get; set; }
}
My User class has a property called "NetworkLogin"
My View has something like this:
<%: Html.LabelFor(model => model.BusinessObject.NetworkLogin)%>
<%: Html.TextBoxFor(model => model.BusinessObject.NetworkLogin)%>
Auto-Fill
And my controller, what I'd like to do, is
[HttpGet]
public ActionResult UserIndex(string networkLogin) { }
The problem: The input parameter "networkLogin" is always null. This makes sense, because the actual parameter on the html element is name="BusinessObject.NetworkLogin" and id="BusinessObject_NetworkLogin". However, I don't know what parameter name I should use in my action method. I've tried "businessObject_NetworkLogin" and it doesn't work either.
However, I have this workaround that does work, 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 my View page now says this instead. <%: Html.TextBoxFor(model => model.NetworkLogin)%>
Can someone tell me what the proper naming convention is for default model binding so that I don't have to employ the above workaround?
Thank you!