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
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.
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.
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.
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 { }.
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.
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.
this is works for me!
@Html.Partial("~/Views/NewsFeeds/NewsFeedPartial.cshtml")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With