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
this is works for me!
Could you not copy the partials into the shared folder then just do:
<% Html.RenderPartial("DefinitionDetails", i); %>
and<% Html.RenderPartial("DefinitionEditActions"); %>
You can refer to Views with full paths, like:
Even better, use the T4MVC library, which does the above and makes it (quasi-) strongly-typed. You can refer to any view from any controller or view. You use it like this:
or
Just to clarify which options work exactly:
1) The extension of the view file is required if you supply a path.
2) If you do not supply a path, do not supply the extension.
The examples below assume cshtml files.
Use
RenderPartial
in a code block:Use
Partial
for inline Razor syntax:Note: Apparently
RenderPartial
is slightly faster thanPartial
, but I also expect fully pathed names will be a faster than letting MVC search for the file.If you are producing partials in a loop (i.e. from a collection in your view model), it is likely you will need to pass through specific viewmodels:
e.g.
I just had to do all this on a project and found the marked answer a little misleading.