Reputation: 5592
I am trying to render a partial page inside a partial page. So i have in my layout page a call to my partial CreateMenu and here i pass the model from the layout page. This works perfect. Now inside the CreateMenu partial i am trying to call MenuItem with the same syntax but then it fails. Visual studio shows the path as red (i know to 100% that it exists).
How can i render a partial from inside a partial.
MenuPartial's call to the render:
@Html.Partial("~/Models/Default/UserControls/_MenuItem.cshtml", Model.Modules[i])
Model.Modules[i] consists of MvcModule objects.
MenuItem:
@model Models.Default.Classes.MvcModule
<li class="@{if (Model.CanExpand) {<text>fullwidth</text>} else {<text>nodrop</text>}} first_fullwidth">
...
This results in a compilation error:
Compiler Error Message: CS0115: "ASP._Page_Models_Default_UserControls__MenuItem_cshtml.Execute()": Es wurde keine passende Methode zum Überschreiben gefunden. Line 46: public override void Execute() {
Sorry for the German text. I have tried to get it to output English instead but VS 2010 refuses to change the settings =/
Upvotes: 2
Views: 2011
Reputation: 2782
I don't think this is a nested partial issue. You should be able to nest partials without any problem. It looks like the partial you're trying to render is in the ~/Models/Default/UserControls
directory. This isn't a place the default view engine looks for views. Try copying the web.config
file from your Views
directory into the Models
directory.
If it were me, I would try to avoid storing views outside of the Views directory if at all possible to avoid weird issues like this.
Upvotes: 2