IActionResult overloading

Posted: June 17, 2019 at 1:28 AM Quote #238035
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.
This post/answer is useful
-1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: June 17, 2019 at 3:09 AM Quote #238038
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
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Thank's,
Sagar Kayasth

NopAdvance - nopCommerce Solution Partner
Website: https://nopadvance.com

We are native nopCommerce nerds...

For project inquiries: [email protected]
Posted: June 17, 2019 at 4:00 AM Quote #238041
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?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: June 17, 2019 at 4:26 AM Quote #238043
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 post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Thank's,
Sagar Kayasth

NopAdvance - nopCommerce Solution Partner
Website: https://nopadvance.com

We are native nopCommerce nerds...

For project inquiries: [email protected]
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2019
Learn more