I have one razor layout this layout spread across all my views.
Until today navigation menu was (separate controller) in this layout. But now this menu has dynamic data. And I can't keep it anymore in layout page.
So should I render this navigation menu in each view or there is some other way to make it only once and just pass data to it?
This is how I render navigation menu in razor layout:
@Html.Action("CommonMenu", "Navigation", new { area = "CityPage" })
In CommonMenu view I have home link:
<li> @Html.ActionLink("Home", "Index", "Home", new { area = "CityPage", city = ViewBag.City, countryCode = ViewBag.CountryCode }, null)
And I open one page with that menu. When I click home I expect to go to home of the city home (like UK, London).
But I can go from this page to some other city (like CH, Zurich).
And now I need to rebind whole navigation menu.
And I don't know can I do that if I render menu in razor layout?
Update
This is how I go from one city page to another:
@Html.ActionLink("Go To London", "Index", "Home", new { area = "CityPage", city = "London", countryCode = "UK" }, null)
When I click on this link mu 'CommonMenu' action is called:
[ChildActionOnly]
public PartialViewResult CommonMenu(string countryCode, string city)
{...
But from some reason this action is called a few times:
First time both values are null.
Second time values are UK,London.
Third time are null.
And this couse my page to break.