Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This doesn't seem quite right, but I found that if I name the drop down list with {nameOfInputParameter}.{propertyName} it loads AND posts correctly. So, if the form in question was posting to a method taking a parameter of the same type as the form's model called "myModel" the dropdown for family could be set up like this:</p> <pre><code>&lt;%= Html.DropDownList("myModel.family", typeof(EnumFamily), Model.Family)%&gt; </code></pre> <p>This renders with an id of myModel_family and a name of myModel.family. I'm not sure how to feel about this, it seems a bit off to me. But it does seem to be working so far. It does introduce a new problem though. You can no longer initialize textboxes, etc... like so:</p> <pre><code>&lt;%= Html.TextBox("name") %&gt; </code></pre> <p>This will load the values correctly, but when you post to the controller method taking "myModel" as a parameter the values aren't recognized as part of the object being submitted. So we need to include the parameter name in our input name.</p> <p>However, the following does not resolve to a value, at least using the default model binder (I'm wondering if digging around in there is going to hold the best answer to this question):</p> <pre><code>&lt;%= Html.TextBox("myModel.name") %&gt; </code></pre> <p>So you need to do this:</p> <pre><code>&lt;%= Html.TextBox("myModel.name", Model.Name) %&gt; </code></pre> <p>This is all getting pretty gross (especially on pages where I need to be able to deal with situations where the model is null). Hopefully someone else has a better idea :)</p>
    singulars
    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.
    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