Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RenderPartial a view from another controller (and in another folder)

I two database entities that i need to represent and i need to output them in a single page.

I have something like this

Views Def ViewA ViewB Test ViewC

I want to ViewC to display ViewA, which displays ViewB.

Right now i'm using something like this:

// View C <!-- bla --> <% Html.RenderPartial(Url.Content("../Definition/DefinitionDetails"), i); %>   // View A <!-- bla --> <% Html.RenderPartial(Url.Content("../Definition/DefinitionEditActions")); %> 

Is there a better to do this? I find that linking with relative pathnames can burn you. Any tips?

Any chance I can make somehtiing like...

Html.RenderPartial("Definition","DefinitionDetails",i); ?

Thanks for the help

like image 766
George Silva Avatar asked May 21 '10 05:05

George Silva


People also ask

How do you call a partial view from another view?

To create a partial view, right click on the Shared folder -> click Add -> click View.. to open the Add View popup, as shown below. You can create a partial view in any View folder. However, it is recommended to create all your partial views in the Shared folder so that they can be used in multiple views.

How do you return a partial view from controller?

In ASP.NET Core MVC, a controller's ViewResult is capable of returning either a view or a partial view. In Razor Pages, a PageModel can return a partial view represented as a PartialViewResult object. Referencing and rendering partial views is described in the Reference a partial view section.

How to render a partial view from another controller?

You can render a partial view (which can be shared between controllers as in (1)) within the current view using Html.Partial (). You can use Html.Action () to invoke an action on a different controller and render the results within the current view.

How does renderpartial () work in SharePoint?

It works when you have the partial view located in the Shared folder. If your partial view is located in a different folder then you will have to mention the full path of view as shown below. RenderPartial () is a void method that writes the output to the response stream. The “void” method in C# needs a”;” and hence must be enclosed by { }.

What are the overloaded versions of renderpartial in MVC?

There are 4 overloaded versions available for the RenderPartial method in ASP.NET MVC Framework as shown in the below image. partialViewName: The name of the partial view. viewData: The view data for the partial view. model: The model for the partial view.

How to render partial view in Parent View in MVC?

You can render the partial view in the parent view using the HTML helper methods: @html.Partial (), @html.RenderPartial (), and @html.RenderAction (). The @Html.Partial () method renders the specified partial view. It accepts partial view name as a string parameter and returns MvcHtmlString.


1 Answers

this is works for me!

@Html.Partial("~/Views/NewsFeeds/NewsFeedPartial.cshtml") 
like image 158
Ravinder Singh Bhanwar Avatar answered Sep 20 '22 15:09

Ravinder Singh Bhanwar