LINQ to Entities does not recognize the method 'System.String ToString()'
method, - MVC4
im working in mvc and have update my database because de first migrations.
now i have an error which i can´t understand what i have to do. i have
search and read about this error and try it.
but i can´t put this to work hope that someone can help me with this.
What i try to do is select the data from my table in the database and
insert into the dropdownlist where the user can select one.
Error:
LINQ to Entities does not recognize the method 'System.String ToString()'
method, and this method cannot be translated into a store expression.
my controller code:
public ActionResult Addnew()
{
var dba = new DefaultConnection();
var query = dba.blob.Select(c => new SelectListItem
{
Value = c.id.ToString(),
Text = c.name_company,
Selected = c.id.Equals(3)
});
var model = new Companylist
{
xpto = query.AsEnumerable()
};
return View(model);
}
View:
@Html.DropDownListFor(m => m.name_company, Model.xpto, "--Select One--")
Note: The error shows in the view.
Model:
public int id { get; set; }
public string name_company { get; set; }
public IEnumerable<SelectListItem> xpto{ get; set; }
public class DefaultConnection : DbContext
{
public DbSet<Mylist> blob { get; set; }
}
Thanks in advance
No comments:
Post a Comment