I m new in MVC framework. my query is i have to receive data from database sql
database. and display in .cshtml
.plz help….
public ActionResult Index()
{
var model = (from p in am.AMS_Page_Accesses
where p.Role_id == "m"
select new {
p.Name,
p.Id,
p.Link
}).ToList();
var abc= new linkname
{
}
return View(abc);
}
Model
public class linktab
{
public string id { get; set; }
public string Name { get; set; }
public string link { get; set; }
}
public class linkname
{
public List<linktab> menu { get; set; }
}
in .cshtml
@foreach (var a in Model)
{
<div>a.Name</div>
<div>a.Id</div>
<div>a.Link</div>
}
You did not show what exactly is your view’s model, according to the error you got it seems you did not specify it at all (using the
@modeldirective).Try this
In your view: