简体   繁体   English

列表问题的最佳重载

[英]The best overload for List issue

@Html.DropDownList(expression: model => model.CategoryID, 
   new List<SelectListItem>(Model.CategorySelectListItem, dataValueField: "Value",
   dataTextField: "Text"),htmlAttributes:new {@class = "form-control"})

This is my code, what does the error mean and how do I fix it?这是我的代码,错误是什么意思,我该如何解决?

What you need is a new instance of SelectList actually not a List of SelectListItem , change your code like this and it works fine:您需要的是SelectList SelectListItem List ,像这样更改您的代码,它可以正常工作:

@Html.DropDownList(expression: model => model.CategoryID,
      new SelectList(Model.CategorySelectListItem, dataValueField: "Value", 
      dataTextField: "Text"),htmlAttributes:new {@class = "form-control"})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM