Plugin ActionFilter ViewModel

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

I have managed to tap into the product save button action using code below:

public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            if ((controllerContext.Controller is ProductController
                && actionDescriptor.ActionName.Equals("Edit", StringComparison.InvariantCultureIgnoreCase)
                && controllerContext.HttpContext.Request.HttpMethod == "POST"))
            {
                return new List<Filter>() { new Filter(this, FilterScope.Action, 0) };
            }
            return new List<Filter>();
        }

The next step i would like to do is to get the view model of my plugin. It is a custom tab in product page. I have added the custom tab using IConsumer<AdminTabStripCreated>. The problem is that in the filter, I only managed to get nop.admin productcontroller product model. How can i get my custom tab model when product page save button is fired?
6 years ago
Hi,

You need to add one more button into your custom view.


        [HttpPost]
        [FormValueRequired("customButton")]
        public ActionResult MyMethod(MyModel model)
        {
            //your code
        }



This is view page code


...
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="options">
            <button type="submit" name="customButton" class="k-button" value="customButton">
                    @T("Admin.Common.Save")
                </button>
        </div>
    </div>
}
...


When ever you click into customButton button than get call to MyMethod with your model value.

Hope this will help you.

Thanks,
6 years ago
Hi,

I'm trying to access my plugin controller when product page save button is clicked. Currently, when product save is clicked, it will call to nop.admin product controller. I would like call my plugin controller after/before with my plugin view model.
6 years ago
cheefi wrote:
Hi,

I'm trying to access my plugin controller when product page save button is clicked. Currently, when product save is clicked, it will call to nop.admin product controller. I would like call my plugin controller after/before with my plugin view model.


I think it's not possible (I am not sure)to get two model value at same event.

You need to add one more button into your view page into your custom tab in product edit page.

Once you click on that custom button than you get value of your model into your pluguin controller's method.

Hope this will help you.

Let me know for further help.

Thanks,
6 years ago
Hi,

I see. Thanks for the help.
6 years ago
Hi,

Your welcome.

Hope my solution is work for you.

Let me know if you you have any further query.

Thanks,
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.