2

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 =/

3
  • Any chance of translating that German to English, and supplying the code for the Execute method the error is referring to? Commented Jul 1, 2011 at 13:45
  • Its the mvc framework that is producing that code. It tries to execute the partial view and it fails. The error says: No suitable method found to override. Commented Jul 1, 2011 at 14:06
  • In visual studio 2010 i get "Cannot resolve partial view: 'path'". I know that it is there. Commented Jul 1, 2011 at 14:14

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

So easy. The MainMenu got created there for some reason and that had always worked. Moved them to the views folder and poff it worked. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.