I need to select the dropdown in html helper. I pass my data in IEnumerable using ViewData please some one help me how to select it with value.
My Code is
If the property your binding to is named BrandMaster
then it should be
@Html.DropDownListFor(m => m.BrandMaster, ViewData["Brand"] as IEnumerable, new { @class = "form-control Repeat TableMust"})
If the value of BrandMaster
matches the value of one of the SelectList items, then it will be selected by default.
Always use the strongly types helpers!
Edit
To use create a dropdown for the property of a collection, you need to use a custom EditorTemplate
for your model
public class MyModel
{
public int BrandMaster { get; set; }
public string AnotherProperty { get; set; }
}
MyModel.cshtml (in Views/Shared/EditorTemplates
@model MyModel
@Html.DropDownListFor(m => m.BrandMaster, ViewData["Brand"] as IEnumerable, new { @class = "form-control Repeat TableMust"})
@Html.TextBoxFor(m => m.AnotherProperty)
Main View
@model IEnumerable
@using (Html.BeginForm())
{
@Html.EditorFor(m => m, new { Brand = ViewData["Brand"])
....
}