Reputation: 1962
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
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.
Upvotes: 0
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