I am building a navbar with bootstrap in MVC 5 .ASP. I am populating the navbar buttons with category ("types") of hospitals.
This error occurs in the PublicViewResults
Menu constructor:
Object reference not set to an instance of an object.
This is my NavController Constructor:
public PartialViewResult Menu()
{
IEnumerable<string> Catagory = repository.Hospitals
.Select(x => x.categories)
.Distinct()
.OrderBy(x => x);
return PartialView(Catagory);
}
And the following is my Hospital
class:
public class Hospital
{
public int Id;
public string Name;
public string City;
public string State;
public string Zip;
public string Beds;
public string categories;
}
Additionally, the navbar bootstrap design is written in CSHTML:
*<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class = "navbar navbar-inverse" role = "navigation">
<a class = "navbar-brand" href="#">HOSPITAL RY</a>
</div>
<div class= "row panel">
div id = "Type" class ="col-xs-3">
@Html.Action("Menu", "Nav")
</div>
<div class = "col-xs-8">
@RenderSection("Body")
</div>
</body>
</html>*
My question is: How to use the Category
value for Hospital ACUTE
or CHILDREN
to populate the navbar categories to be displayed on the left sidebar?
Currently, categories
retrieves null
value and not correspond with this information in the repository below:
private List<Hospital> data = new List <Hospital>
{
new Hospital{Id = 1, Name = "Kaiser Permentae Irvine " ,City = "Irvine", State= "CA" , Zip = "9003" , Beds= "100" ,categories = "Acute" },
new Hospital{Id = 2, Name = "Kaiser Permentae Los Angeles " ,City = "Los Angeles", State= "CA" , Zip = "90213" , Beds= "200" ,categories= "Acute"},
new Hospital {Id = 3, Name = "Kaiser Permentae San Fransico " ,City = "San Fransico", State= "CA" , Zip = "9500" , Beds = "300" ,categories = "Children"}
};
Aucun commentaire:
Enregistrer un commentaire