Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Megha 10 posts 80 karma points notactivated
    Feb 08, 2023 @ 10:48
    Megha
    0

    How To call An Action In Umbraco Controller?

    Hello All,

    I created an Umbraco DocumentType with the alias Product and created a controller that inherits

    Umbraco.Web.Mvc.RenderController

    I added two Actions, one is the Product action and the other is called Brand.I have Document type & Template of Product name and Brand.

    enter image description here

    When I put the url like this: localHost/Product/Brand it shows: Page not Found

    So please help me How can I fire the Brand Action from the Product controller?

    Thanks!

  • Dhanesh Kumar MJ 167 posts 543 karma points MVP c-trib
    Feb 09, 2023 @ 06:51
    Dhanesh Kumar MJ
    0

    Hi Megha,

    To achieve this, please create content of type Product and choose the template as Brand, Publish the content and browse the URL from the Info tab or create content as above & browse like this https://domain/page-url?altTemplate=templatealias (in your case Brand)

    Please see the documentation here https://docs.umbraco.com/umbraco-cms/reference/routing/custom-controllers#example-hijacking-route-requests-to-a-product-for-an-alternative-amp-template

  • Megha 10 posts 80 karma points notactivated
    Feb 09, 2023 @ 11:05
    Megha
    0

    Thanks !! It's working but when it return i got these error : enter image description here

  • Dhanesh Kumar MJ 167 posts 543 karma points MVP c-trib
    Feb 09, 2023 @ 11:26
    Dhanesh Kumar MJ
    0

    Hi Megha,

    This is because the brand template expecting BrandModel, but your are return ProductModel.

       Public IActionResult Brand()
        {
         return CurrentTemplate(CurrentPage);
        }
    

    CurrentPage is actually ProductModel because you are on the content of type Product (doctype), but using Brand Template.

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<change to productmodel> in BrandTemplate cshtml file 
    

    or simply change to

     @using Umbraco.Cms.Core.Models
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModel>
    

    ContentModel is the base model, please go through the documentaion for better understanding.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies