Override HomepageProducts ViewComponent

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 1 an
Is it possible to override the HomepageProducts viewComponent
Il y a 1 an
Yes, It is possible to override to component view.

Use IViewLocationExpander for override view.
public class ViewLocationExpander : IViewLocationExpander
{
  public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
  {
    if (context.AreaName == null && context.ViewName == "Components/HomepageProducts/Default"){
      viewLocations = new string[] {"your view path"}.Concat(viewLocations);
    }
return viewLocations;
  }  

public void PopulateValues(ViewLocationExpanderContext context)
        {
            //do nothing here
        }
}
Il y a 1 an
Hi,
in this way you can use your custom View file(cshtml file) but how can I use my ViewComponent file? I would like to use my custom view file(cshtml and I can) and my custom viewcomponent file(like HomepageProductViewComponent.cs).

Thanks
Il y a 1 an
STESAMO wrote:
Hi,
in this way you can use your custom View file(cshtml file) but how can I use my ViewComponent file? I would like to use my custom view file(cshtml and I can) and my custom viewcomponent file(like HomepageProductViewComponent.cs).

Thanks


Hello STESAMO,

Why do you have to use your custom viewcomponent file(like HomepageProductViewComponent.cs)?
Are there any code related changes?
Il y a 1 an
Yes, I need to make some changes; the only way I found is to ovverride the Factory that populate the model.
Il y a 1 an
Yes, You need to override model for changes. if you don't want to override it, then you can use model prepare event.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.