Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC model binding naming convention for child objects?
    primarykey
    data
    text
    <p>I'm having trouble with default model binding naming convention when there is a child property. For example:</p> <p>I have a ViewModel which looks something like this:</p> <pre><code>public class UserViewModel { public User BusinessObject { get; set; } } </code></pre> <p>My User class has a property called "NetworkLogin"</p> <p>My View has something like this: &lt;%: Html.LabelFor(model => model.BusinessObject.NetworkLogin)%> &lt;%: Html.TextBoxFor(model => model.BusinessObject.NetworkLogin)%> Auto-Fill <br /></p> <p>And my controller, what I'd like to do, is</p> <pre><code> [HttpGet] public ActionResult UserIndex(string networkLogin) { } </code></pre> <p>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.</p> <p>However, I have this workaround that does work, but I don't like it. I add this to my ViewModel:</p> <pre><code> public string NetworkLogin { get { if (BusinessObject == null) BusinessObject = new User(); return BusinessObject.NetworkLogin; } set { if (BusinessObject == null) BusinessObject = new User(); BusinessObject.NetworkLogin = value; } } </code></pre> <p>And my View page now says this instead. &lt;%: Html.TextBoxFor(model => model.NetworkLogin)%></p> <p>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?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload