This is my select list from model.
public IEnumerable<SelectListItem> ServiceCycleList
{
get
{
var Item = new List<SelectListItem>
{
new SelectListItem { Text = "Yearly", Value = "12" },
new SelectListItem { Text = "Quarterly", Value = "3" },
new SelectListItem { Text = "Monthly", Value = "1" }
};
return Item;
}
}
I want to Create one dropdown list for this select list. How Can I to that?
如果模型视图可以使用它,则可以这样创建DropDownList
:
@Html.DropDownListFor(model => model.YourModelProperty, new SelectList(Model.ServiceCycleList, "Value", "Text"), "Please Select...")
Based on your comment above, your action method is returning a view without a model, and thus the error you get is the model is null.
public ActionResult Index(..)
{
.
.
return View(); // missing model reference
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.