Hello,
It looks like the mistake is there in the
@Html.Partial("TopMenu", Model)
part. When the _Layout partial page is executed, model value is null. Had you been passing the Model to the partial view it would have been ok. If you see, your function is an Action Method, that is returning a Strongly Typed View from the controller. So you should call the Action method instead of the Partial View.
So if you call the
@Html.Action("TopMenu","CatelogController")
then it will fetch the menus, Send them to the partial view, Build the HTML and will be injected in to the _Layout.
Hope this helps.
I have created a dummy project on uploaded to Github. You can download and check that.
Link to Github Repository. Click here to download[
^]
Have a look at the
HomeController
and
_Layout.cshtml
page