Reputation: 9570
I have a drop down that is created like this:
@Html.DropDownListFor(x => x.SelectedBrandCode,
new SelectList(Model.Brands, "Value", "Text"),
"-Select Brand-")
it works fine, but now I need another dropdown , this second one is NOT bound to a property in the model. This second one should be populated from the same List<>
, but it is just for an AJAX search, there is no need to add an extra property in the Model for this. I would like to be able to set the id
and name
for this second one. If that is not possible - I can just make a unique class. But the only options that I see from the built in HTML Helpers are for creating an input for a property in the model. Is there any way to do this? or am I stuck with a foreach()
loop on the list and manually making a <select>
element?
Upvotes: 1
Views: 54
Reputation: 82267
No matter what the form on the page contains, the model being bound server side in the actionresult will define what data is actually accepted from the request.
Thus, even if an extra name, id, or whatever is sent from the client, only what is defined as accepted will be captured. This is good for many reasons, one of the main reasons being that it protects you from malicious users posting false data.
So just use a string for the name of the drop down and it will show up on the page, but not affect the server post
@Html.DropDownList("BrandDropDown",
new SelectList(Model.Brands, "Value", "Text"),
"-Select Brand-")
Upvotes: 1