Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is a good way to edit two values with a single ASP .NET MVC dropdown?
    primarykey
    data
    text
    <p>A record is uniquely identified by its <code>Kind</code> and <code>RecordId</code>. </p> <p>I have a set of records that I want to display as a dropdown, and on submitting I'd like to get <code>SelectedKind</code> and <code>SelectedRecordId</code> for further processing.</p> <p>The problem is, <strong>I want these values to be processed separately, but there should be only one dropdown</strong>.<br> What is the best practice for doing this?</p> <p>My suggestions:</p> <h3>Option 1</h3> <p><strong>Populate the dropdown with strings like <code>"Kind_RecordId"</code> and set up a JavaScript <code>change</code> handler which will parse the string and set hidden field values.</strong></p> <p>However I don't quite like the idea of having string operation logic in different places (in controller when populating the dropdown, and in view when parsing the values). Should I move <code>SelectItem</code> populating logic into view as well, and keep my business objects in the view model instead?</p> <p>It also bugs me that in rare case when JavaScript is disabled, the user will not be able to sumbit the form at all.</p> <h3>Option 2</h3> <p><strong>Expose a unique <code>"Kind_RecordId"</code>-like string property in my form model, and let the model parse it (or fill it) through strong-typed accessor properties for the controller?</strong></p> <p>This seems like a better way but I'm not entirely sure. What I consider good about it is it'll keep all parsing/concatenating logic in view model, and it will not fail when JavaScript is not available.</p> <p>Community thoughts are very appreciated.</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.
 

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