How to change id value when using Html.DropDownListFor helper in asp.net mvc 2.0?
Posted
by chobo2
on Stack Overflow
See other posts from Stack Overflow
or by chobo2
Published on 2010-05-16T01:56:16Z
Indexed on
2010/05/16
2:00 UTC
Read the original article
Hit count: 470
Hi
I have a partial view that has something like this
<%= Html.DropDownListFor(m => m.SelectedProductName, Model.ProductList, "Select a Product") %>
Now you can create a new product and edit a existing product. Both editing and creating use the same form. The create is on the main page on load up. Edit popus up in a jquery u.i model dialog and renders a new partial view.
So as far as the page is concerned is that I have 2 dropdown boxes with the same "id" which is bad since they should be unique. So how do I change the id? So when the edit loads it might have a id of "editSelectedProductName"?
I tried to do this in the view model
public string SelectedProductName{ get; set; }
ViewModelConstructor()
{
SelectedProductName = "EditSelectedProductName";
}
But it seems to not care and keeps using "SelectedProductName" as the product name.
Thanks
© Stack Overflow or respective owner