Override Partial View and use different versions of _RentalInfo.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 года назад
I know we can override a view using
public class ViewLocationExpander : IViewLocationExpander
(...)

What about a partial view ?
In ProductTemplate.Simple.cshtml
we have the line
@await Html.PartialAsync("_RentalInfo", Model, dataDictRental)

How can I call _MyRentalInfo.cshtml instead
Is the only way to put it in the theme folder as _RentalInfo.cshtml so that it is "found" ?

Or is there a way to do it in the program only for a specific template
i.e. I want to call different versions of _RentalInfo.cshtml based on the current template
ProductTemplate.Simple.cshtml uses the default _RentalInfo.cshtml
ProductTemplate.RentalType1.cshtml uses the default _MyRentalInfo1.cshtml
ProductTemplate.RentalType2.cshtml uses the default _MyRentalInfo2.cshtml

By the way ProductTemplate.RentalType1.cshtml belongs so someone else plugin theme so I can not change it
3 года назад
Let me know if below link help you.

https://www.nopcommerce.com/en/boards/topic/85129/how-to-make-custom-view-engine-in-nopcommerce-43
3 года назад
Thanks, I already had a CustomViewExpander
3 года назад
I was thinking if I could check context.ViewName and see _RentalInfo
then I would be able to use some code like

if (context.ViewName == "_RentalInfo")
{
    // Do something
}

But for some reason the all the Html.PartialAsync views that are in the ProductTemplate do not appear. It seems to be only the Components and Full Views that are available in context.ViewName
3 года назад
sangeetshah wrote:
Let me know if below link help you.
https://www.nopcommerce.com/en/boards/topic/85129/how-to-make-custom-view-engine-in-nopcommerce-43

Actually you were right - dont know why I missed it at first

                            if (context.ViewName == "_RentalInfo")
                            {
                                viewLocations = new[] {
                                    $"/Plugins/PluginGroup.Name/Views/FrontView/_RentalInfo.cshtml",
                                }
                                .Concat(viewLocations);
                            }
                            else if (context.ViewName == "_AddToCart")
                            {
                                viewLocations = new[] {
                                    $"/Plugins/PluginGroup.Name/Views/FrontView/_AddToCart.cshtml",
                                }
                                .Concat(viewLocations);
                            }

There is a bit more to it but you can check any Partial View and redirect

Thanks for the Hint
3 года назад
Always happy to help you and all.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.