I have a _layout.cshtml containing this row:
@{Html.RenderPartial("Menu");}
Now I want to pass in a model into this RenderPartial-function. This model can be read from my repository.
How and where(in code) can this be done?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
RenderPartial has an overload that can take an object to send it to the partial view.
Don’t forget to define your @model at the top of your partialview to work with the right object type.
@Html.RenderPartial(“ViewName”,object)
Extra info: MSDN
Edit after comment:
I think it would be easier to create a MenuController that takes in the repository. Then let it create a view which takes in the required repository as it’s model, then with a foreach render every menu-item as actionlinks, passing the menu info to it.
So you would have this in your _layout.cshtml:
This in your MenuController:
And your MenuView:
Would that be any closer to a solution?