Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em><strong>Sorry - just realised that your code was VB and I've answered in C#</em></strong></p> <p>This could be because the model binder is now looking <code>modelname.property</code> instead of just <code>property</code> in the ValueProviders and, previously, because it was a direct action method parameter, it would have just been looking for <code>property</code>.</p> <p>Now that the model type is a member of another, its property name will be used as a prefix and I <em>don't believe</em> you can remove that requirement (could try <code>Bind(Prefix="")</code> on the parameter, but I don't think that'll work).</p> <p>This is assuming you aren't custom-binding every property and that the <code>DefaultModelBinder</code> is doing some of these properties for you.</p> <p>You should be able to make it work, without changing code, by altering your query string to be <code>?modelname.property=[value]</code>. If you're using a Form, then you should consider using the <code>Html.EditorFor</code> extension method - as it takes care of model naming (so long as your ViewModel member names and input model names are consistent). But as an example from the query string:</p> <pre><code>public class MyObject{ public string StringValue { get; set; } } public class MyObjectOuter{ public MyObject Nested { get; set; } } public ActionResult Index(MyObjectOuter obj); </code></pre> <p>The obj.Nested.StringProperty value can be filled with: <code>/Index?Nested.StringValue=hello%20world</code> because the <code>obj</code> prefix is implicit anyway.</p> <p>If you don't like this, you have a couple of options:</p> <p>1) Change the signature of the method to take two parameters:</p> <pre><code>public ActionResult Index(MyObjectOuter outer, MyObject nested) </code></pre> <p>And then in the body you immediately copy <code>nested</code> to the <code>obj.Nested</code> property. This is a little bit hacky - but it'll work.</p> <p>2) Manually force the bind of your class' properties to use non-prefixed values from the <code>ValueProviders</code> (but then you're limiting your model type to only work with certain types of request - which isn't exactly flexible).</p> <p>3) Or, like I said earlier, if these properties are being bound from an Http Form, use <code>Html.EditorFor</code> to generate the markup - it automatically generates inputs with the correct names, so long as they don't change from input->output.</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