IActionResult overloading

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hello,

I need to override Admin action result for add product to order in my plugin.
But I am getting this error.

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

I have write this code.

public class OrderController : Nop.Web.Areas.Admin.Controllers.OrderController
{
    public virtual IActionResult AddProductToOrder(int orderId)
    {
  //prepare model
        //[I will prepare model as per my requirement]
  
  return View(Model);
    }
}

Please submit your suggestions.
4 years ago
Hello p.d.dobariya13,

Use action filter for prepare your model.
You can override  PrepareAddProductToOrderSearchModel method in OrderModelFactory as per your requirement.

public partial class PluginModelFactory : IOrderModelFactory,OrderModelFactory
{
         // your fields
           public PluginModelFactory():base(// needed fields for base)
           {

           }
          
           public override AddProductToOrderSearchModel
            PrepareAddProductToOrderSearchModel(AddProductToOrderSearchModel searchModel, Order order)
          {
             // prepare your code as per your requirement
          }
}

please register in your DependencyRegistrar.cs file.

Thank you.
Sagar Kayasth
4 years ago
Thanks for your suggestion.

This is service or factory override.

But I need a solution for IActionResult override.

suppose I in the order Edit ActionResult I need to change and result a view that is in my plugin
Because I need to change in edit order view  pages.

in this case I need to override below method

public virtual IActionResult Edit(int id)
{
//Model prepare
return View("~/Plugin/Views/Order/Edit.cshtml", Model);
}

is there any way to override this or not?
4 years ago
p.d.dobariya13 wrote:
Thanks for your suggestion.

This is service or factory override.

But I need a solution for IActionResult override.

suppose I in the order Edit ActionResult I need to change and result a view that is in my plugin
Because I need to change in edit order view  pages.

in this case I need to override below method

public virtual IActionResult Edit(int id)
{
//Model prepare
return View("~/Plugin/Views/Order/Edit.cshtml", Model);
}

is there any way to override this or not?


You cannot directly do that using route override, use action filter instead.
Please follow the below link for your answer.
https://www.pronopcommerce.com/overriding-intercepting-nopcommerce-controllers-and-actions

Thank you
Sagar Kayasth
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.