Override HomepageProducts ViewComponent

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
один год назад
Is it possible to override the HomepageProducts viewComponent
один год назад
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
        }
}
один год назад
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
один год назад
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?
один год назад
Yes, I need to make some changes; the only way I found is to ovverride the Factory that populate the model.
один год назад
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.