Copied to clipboard

Flag this post as spam?

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


  • Dharmesh 50 posts 210 karma points
    May 30, 2017 @ 06:36
    Dharmesh
    0

    Custom controller in Merchello

    Hi,

    I want to create a custom controller and want to get execute action inside that controller on form submit (customize code). I tried it with umbraco and it worked exactly as required, but the same way it's not working with merchello. Please help guys.

    Thanks & Regards
    Dharmesh

  • Dharmesh 50 posts 210 karma points
    May 30, 2017 @ 13:52
    Dharmesh
    0

    Wondering if anyone has implemented custom controller in merchello on form submit ?

  • Frans Lammers 57 posts 400 karma points c-trib
    May 30, 2017 @ 14:23
    Frans Lammers
    1

    Hi Dharmesh,

    You can do it the same way as a standard Umbraco SurfaceController, but you have to inherit it from MerchelloSurfaceController.

    Example:

         public class myCustomController : MerchelloSurfaceController
            {
    
                public ActionResult myAction()
                {
                    return View(new myModel);
                }
    
    
                 [HttpPost]
                 [ValidateAntiForgeryToken]
                 public ActionResult myActionResult(MyModel myModel) 
                 {
                       if (!ModelState.IsValid) 
                       { 
                              return CurrentUmbracoPage();
                       }
                       return...;
                 }
    }
    

    You can call this for instance in a view, example:

    @Html.Action("myAction", "myCustomController")
    
  • Dharmesh 50 posts 210 karma points
    May 31, 2017 @ 07:36
    Dharmesh
    0

    Hi Frans,

    Thanks a lot for your reply. I tried with your suggestion and it worked fine, But when i try to submit the form, i'm not able to invoke the action (HttpPost) of the controller. What should we pass as an action attribute of the form to invoke the custom action of the custom controller in merchello ?

    Thanks again :) Waiting for your reply :)

    Thanks & Regards
    Dharmesh

  • Frans Lammers 57 posts 400 karma points c-trib
    May 31, 2017 @ 07:43
    Frans Lammers
    0

    Hi Darmesh,

    By using:

    @using (Html.BeginUmbracoForm<namespace.myCustomController>("myActionResult"))
    {
    }
    

    in the view, the submit-button within the view will invoke the POST-action.

  • Dharmesh 50 posts 210 karma points
    May 31, 2017 @ 08:26
    Dharmesh
    0

    Hi Frans,

    Thanks, I tried this way but not actually worked. I'm getting this kind of error on form submit:

    "Cannot create an abstract class."

    Look at the screenshot attached here:

    enter image description here

    Actually I want to customize checkout form and on form submit i want to redirect to custom action of my custom controller. when i try to inspect element and check the form action attribute, seems like it's not changing the action attribute.

    I used this form html helper:

    @using (Html.BeginUmbracoForm<RootDir.App_code.Controllers.CustomCheckoutController>("CustomCheckoutConfirmation"))
        { }
    

    But on inspecting form html tag from browser, it displays it's action attribute as:

    form action="/checkout/confirm-sale/" enctype="multipart/form-data" method="post">

    Thanks & Regards
    Dharmesh

  • Frans Lammers 57 posts 400 karma points c-trib
    May 31, 2017 @ 08:43
    Frans Lammers
    100

    This sounds like a problem with the parameter of the actionresult. That cannot be an abstract class, because of bindingproblems.

  • Dharmesh 50 posts 210 karma points
    May 31, 2017 @ 08:54
    Dharmesh
    0

    Hi Frans,

    Thanks for your immediate replies to my questions. It was the parameter type that created the issue. The type was different from it was passed from view that's why i was getting the kind of error i mentioned in my previous post. Thank you so much :)

    Thanks & Regards
    Dharmesh

Please Sign in or register to post replies

Write your reply to:

Draft