Jaqen H'ghar
Jaqen H'ghar

Reputation: 1879

How to set drop down list selected item in editor template?

I have a view in MVC bound with model. Model is about person information. Itcontains a member for storing country. I have displayed the model information in a grid on view using an extension. I have created dropdown editor template for country for editing the person's country. But the problem is this drop down always shows the first entry as default selected for all persons. Whereas, I want respective person's country being selected.

Is there any way to achieve this?

Thanks, Kapil

Upvotes: 2

Views: 1368

Answers (1)

FLY
FLY

Reputation: 2459

<select>
 <option value="1" >first option</option>
 <option value="2" selected="selected">this option is selected</option>
</select>

you have to compare the stored value with the option value if true echo the 'selected part'

try looking here: ASP.NET MVC Html.DropDownList SelectedValue

Upvotes: 1

Related Questions