Override HomepageProducts ViewComponent

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