Reputation: 1065
I have one Partial View as follows
_MyNav.cshtml
<ul>
<li>
@Html.ActionLink("Link1", "Index", "Link",new { id="" }, null)
</li>
<li>
@Html.ActionLink("Link2", "Index", " Link ",new { id="1" }, null)
</li>
<li>
@Html.ActionLink("Link3", "Index", " Link ",new { id="2" }, null)
</li>
</ul>
I included the partial view in two places in my main layout file. @Html.Partial("_MyNav"). One of the partial views needs to have all the links the other one needs to have two links.
Is there anyway that I would be able to hide one of the links in _MyNav by passing the parameter?
Upvotes: 1
Views: 240
Reputation: 1039110
Make your partial strongly typed to a model (boolean in your case):
@model bool
<ul>
<li>
@Html.ActionLink("Link1", "Index", "Link",new { id="" }, null)
</li>
<li>
@Html.ActionLink("Link2", "Index", " Link ",new { id="1" }, null)
</li>
@if (Model)
{
<li>
@Html.ActionLink("Link3", "Index", " Link ",new { id="2" }, null)
</li>
}
</ul>
and then if you want to have 3 linkks:
@Html.Partial("_MyNav", true)
and if you want to have 2 links:
@Html.Partial("_MyNav", false)
Of course if you need to pass more complex information to the partial than just a boolean value you would define a view model and then make your partial strongly typed to this view model.
Upvotes: 1