为了账号安全,请及时绑定邮箱和手机立即绑定

控制器错误“Microsoft.AspNetCore.Mvc.Rendering.

控制器错误“Microsoft.AspNetCore.Mvc.Rendering.

C#
犯罪嫌疑人X 2021-06-29 05:53:44
我想在 MVC 中创建一个 SelectList 下拉列表。我更喜欢选择列表在存储库中,而不是在控制器中。我如何调用存储库,甚至不引用模型中字段的名称。我唯一想提到的是存储库。我收到此“Microsoft.AspNetCore.Mvc.Rendering.SelectListItem”的错误 此资源还没有帮助: 为什么我在 DropDownList 中收到“System.Web.Mvc.SelectListItem”?我在网上阅读了很多例子,这是原始代码,原始代码:ViewData["ProductTypeId"] = new SelectList(_context.ProductType, "ProductName", "ProductDescription");我试图让代码像这样工作:接收错误:“Microsoft.AspNetCore.Mvc.Rendering.SelectListItem” ViewData["ProductTypeId"] = new SelectList(_producttyperepository.GetAllLookupKey());    public IEnumerable<SelectListItem> GetAllLookupKey()    {       return  (from ptin _context.ProductType pt                       select new SelectListItem                       {                           Value = pt.ProductTypeName,                           Text = pt.ProductDescription                       });    }        <div class="form-group">            <label asp-for="ProductType" class="control-label"></label>            <select asp-for="ProductType" class="form-control" asp-items="ViewBag.ProductTypeId"></select>            <span asp-validation-for="ProductType" class="text-danger"></span>        </div>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 202 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信