jamala g

jamala g

  • NA
  • 34
  • 6.5k

The ViewData item that has the key ‘Name’ is of type System

Oct 15 2019 12:21 AM
I'm new to asp mvc and Developing a Web Application in which i have told to create Roles I am using Identity framework The Error Is Given Dont Know What to with That
The ViewData item that has the key 'Name' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>'.
 
this is the Code
 
Controller
  1. [AllowAnonymous]  
  2. public ActionResult Register()  
  3. {  
  4. ViewBag.Name = new SelectList(_db.Roles.ToList(),"Name","Name");  
  5. return View();  
  6. }  
View Code
  1. <div class="form-group">  
  2. @Html.LabelFor(m => m.Name, new { @class = "col-md-2 control-label" })  
  3. <div class="col-md-10">  
  4. @Html.DropDownListFor(m => m.Name,ViewBag.Name as SelectList ,"--Select Role--",new { @class = "form-control" })  
  5. </div>  
  6. </div>  

Answers (5)