Reputation: 71
I have a shared view where I am hiding or showing header based on the Plan exists or not. But I am getting this error 'Cannot perform runtime binding on a null reference' at this line @if (Model != null && Model.Plan > 0)
, not sure why. What I am missing here?
Here is my code:
@using System.SharedConfig
@{
var plan = ConfigurationManager.AppSettings["planString"];
}
<ul class="nav nav-pills nav-justified internal-nav">
<li data-navigation-pill="insurance">@Html.ActionLink("Insurance", "Main", "Insurance")</li>
@if (Model != null && Model.Plan > 0)
{
<li data-navigation-pill="plan">@Html.ActionLink(plan, "Main", "Plan")</li>
}
else
{
//The RTPlan link is hidden, so adjust the header according to the design
<style type="text/css">
.nav-justified > li > a {
text-align: left;
padding-left: 88px !important;
}
</style>
}
</ul>
Upvotes: 2
Views: 551
Reputation: 738
You didn't loaded model in your view so view don't know which model you are requesting. When you are returning view from controller you can return model in your return statement like
return View(model);
Add that model in your view.
Like
@model ModelName
Upvotes: 1