anpatel
anpatel

Reputation: 1962

Accessing a partial view from a different control from within an area

Within an MVC view I'd like to access a partial view from a different controller. Before I explain my issue at hand you should know where everything is in my solution:

Areas      
   MyArea    
        Views
         Cont1
           PartialPages
           ViewImIn
         Cont2
            PartialPages
               ViewICall

Now, in ViewImIn.cshtml I call ViewIcall.cshtml like this:

@Html.Partial("~/Views/Cont2/PartialPages/ViewICall.cshtml", Model)

But I keep getting the error stating that the "partial view was not found or view engine does not support searched locatio..."

I've also tried "../Cont2/PartialPages/ViewICall" and variations of it.

Upvotes: 1

Views: 2111

Answers (3)

Chad Kapatch
Chad Kapatch

Reputation: 585

You can also use RenderAction which may or may not be what your looking for. If the Model is different for the ViewICall or you'd like to separate the Model/logic; then you can use RenderAction which will allow you call a Controller method and render the result. If the partial view you're trying to render uses the same Model as your current view, then use RenderPartial.

  • Here is a post by Phil Haack on Html.RenderAction and Html.Action
  • Here is a post on when to use RenderAction and when to use RenderPartial

Upvotes: 0

Jeffrey Lott
Jeffrey Lott

Reputation: 7439

Instead of having a PartialPages folder under Cont2, you should have a Shared folder directly under Views. Then it should be able to found directly with:

@{Html.RenderPartial("ViewICall", Model);}

Upvotes: 0

Forty-Two
Forty-Two

Reputation: 7605

Try calling it like this

 @{Html.RenderPartial("ViewICall");}

Upvotes: 2

Related Questions