Reputation: 1
I'm receiving an error in controller in line model.dropdownuserlist
:
System.Collections.Generic.List<System.Web.Mvc.SelectListItem> to System.Collections.Generic.List<System.Web.WebPages.Html.SelectListItem>
My model is like below
public List<SelectListItem> dropdownuserlist { get; set; }
[Display(Name = "Select User")]
public string uid { get; set; }
and controller is dropdown.cs
.
public ActionResult Dropdown()
{
DropdownModel model = new DropdownModel();
model.dropdownuserlist = dropdownuserlist()
.Select(p =>
new SelectListItem
{
Text = p.Name,
Value = p.Id.ToString()
})
.ToList<SelectListItem>();
return View();
}
I can not figure out how to cast this properly. Any suggestions?
Upvotes: 0
Views: 4792
Reputation: 13010
It looks like you are having a class ambiguity problem being caused by your referenced namespaces. There are 3 ways to deal with this.
See using Directive (C# Reference) for an example of using aliases.
using HtmlSelectListItem = System.Web.WebPages.Html.SelectListItem ;
using MVCSelectListItem = System.Web.Mvc.SelectListItem;
Upvotes: 0
Reputation: 11320
Try
model.dropdownuserlist = dropdownuserlist().Select(p => new System.Web.WebPages.Html.SelectListItem { Text = p.Name, Value = p.Id.ToString() }).ToList();
You are using the wrong namespace.
Upvotes: 1