Open Closed

Can't override UI in CmsKit Blog #3770


User avatar
0
AdamMusson created

I think there is a bug in the CmsKit in that you can't override the model and view as you should be able to do under the normal Abp principles. The OnGet method in the base class cannot be overriden.

How can I solve this as I do not have access to the source code to completely write my own handler by copying everything in the base class and building it up from there?

  • ABP Framework version: v6.0.0-rc.4
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:

InvalidOperationException: Multiple handlers matched. The following handlers matched route data and had all constraints satisfied: Void OnGetAsync(), System.Threading.Tasks.Task OnGetAsync()

  • Steps to reproduce the issue:"
    1. Create a view Index.cshtml in a folder ~Pages/Public/CmsKit/Blogs/ in the Public Website project - this is to override that view
    1. Create a model BlogIndexModel that inherits from **Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs.IndexModel ** This works according to the naming conventions.
    1. Try to create an OnGet or OnGetAsync method so that you can setup the model for your overridden Blogs Page. For example

public BlogPostPublicDto LatestPost { get; set; } public void OnGetAsync() { base.OnGetAsync(); LatestPost = base.Blogs.Items.OrderByDescending(d => d.CreationTime).Take(1).First();

}

This compiles but throws the exception because of the OnGet handler in the base class.

public new void OnGetAsync() to hide the base class implementation also compiles but still get the same Exception as multiple handlers match when you run it.

The fix would normally be to override the method. I've done this with other pages but it doesn't work here.

public override void OnGetAsync() { }

But this doesn't compile as the OnGet method in the base class has not been marked virtual and cannot be overridden. Any help to sort this out would be appreciated.


1 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello,

    I opened a pull-reqeuest on the topic. See: https://github.com/abpframework/abp/pull/14188

    Workaround solution:

    Copy the code of the model class you want to override and paste it into the contents of your own model class. For example: https://github.com/abpframework/abp/blob/dev/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs

    Then update the model on the page to reference your customized model class. For instance: https://github.com/abpframework/abp/blob/317eb03942c49ddbdff09a7a7d7bfcf7ff3dd518/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml#L8

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11