There is no ViewData item of type 'IEnumerable' that has the key country

后端 未结 11 2224
鱼传尺愫
鱼传尺愫 2020-12-03 07:52

While binding dropdown in MVC, I always get this error: There is no ViewData item of type \'IEnumerable\' that has the key country.

<
11条回答
  •  半阙折子戏
    2020-12-03 08:11

    your code is correct because in some cases it does not work, I also do not know where the error comes from but this can help you solve the problem, move the code in the head of the view like this:

    index.cshtml:
    
    @using expert.Models;
    @{
        ViewBag.Title = "Create";
        Layout = "~/Views/Shared/_Layout.cshtml";
        Manager db = new Manager();
        ViewBag.FORM_PRESTATION = new SelectList(db.T_BDE_PRESTATION_PRES.OrderBy(p => p.PRES_INTITULE).Where(p => p.T_B_PRES_ID == null), "PRES_ID", "PRES_INTITULE");
    
    }
    
    
    
    @Html.DropDownList("FORM_PRESTATION", null, htmlAttributes: new { @class = "w3-select ", @required = "true" })

提交回复
热议问题