The type 'Nop.Plugin.CRM.Zoho.ZohoRegistrarActionFilter' is not assignable to service 'System.Web.Mvc.IFilterProvider'.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 8 años
I followed the article @ http://www.pronopcommerce.com/overriding-intercepting-nopcommerce-controllers-and-actions

I got an error:

The type 'Nop.Plugin.CRM.Zoho.ZohoRegistrarActionFilter' is not assignable to service 'System.Web.Mvc.IFilterProvider'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: The type 'Nop.Plugin.CRM.Zoho.ZohoRegistrarActionFilter' is not assignable to service 'System.Web.Mvc.IFilterProvider'.



I created three ActionFilter.cs to do different functionalities. one of them is like:

using System;
using System.Web;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nop.Web.Controllers;
using Nop.Services;
using Nop.Services.Customers;
using Nop.Services.Affiliates;
using Nop.Services.Common;
using Nop.Services.Localization;
using Nop.Services.Helpers;
using Nop.Services.Directory;
using Nop.Services.Logging;
using Nop.Core;
using Nop.Core.Infrastructure;
using Nop.Core.Domain;
using Nop.Core.Domain.Customers;


namespace Nop.Plugin.CRM.Zoho
{
    public class ZohoRegistrarActionFilter : ActionFilterAttribute
    {
        public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {    
            if (controllerContext.Controller is CustomerController &&
                actionDescriptor.ActionName.Equals("RegisterResult",
                StringComparison.InvariantCultureIgnoreCase))     {        
                return new List<Filter>() { new Filter(this, FilterScope.Action, 0) };    
            
            }     return new List<Filter>();
        }
        
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //do stuff

        }

    }
}

I also registered them in DependencyRegistrar.cs as mentioned in the article:

using System;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac;
using Autofac.Core;
using Autofac.Integration.Mvc;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Core.Data;
using Nop.Web.Framework.Mvc;

namespace Nop.Plugin.CRM.Zoho
{
    public class DependencyRegistrar : IDependencyRegistrar
    {

        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {

            builder.RegisterType<ZohoCRMService>().As<IZohoCRMService>().InstancePerLifetimeScope();

            builder.RegisterType<ZohoRegistrarActionFilter>().As<IFilterProvider>();
            builder.RegisterType<ZohoSalesOrderActionFilter>().As<IFilterProvider>();
            builder.RegisterType<ZohoEnquiryActionFilter>().As<IFilterProvider>();

        }

        public int Order
        {
            get { return 1; }
        }
    
    }
}


Could anyone help me to fix it?

Many Thanks,
Amy
Hace 8 años
Make your code like follow:

public class ZohoRegistrarActionFilter : ActionFilterAttribute, IFilterProvider
Hace 8 años
You are rock. it works.

Thanks.
Hace 8 años
wooncherk wrote:
Make your code like follow:

public class ZohoRegistrarActionFilter : ActionFilterAttribute, IFilterProvider



Hi wooncherk,

I am facing another problem regarding ActionFilter.

I tried to override ContactUsSend in the CommonController.cs. But it is not working. I noticed that
[HttpPost, ActionName("ContactUs")]

So after the information is filled into the form, then submit it , the page stays in the ContactUs page.

How could I do in this case?

Many Thanks for all your help.

Amy
Hace 8 años
Capture "ContactUs" instead of "ContactUsSend" in your action filter. ;)
Hace 8 años
I tried using ContactUs, but it will run the code when the contact us form shows. The code need to be ran after the form is submitted.
Hace 8 años
amyniu wrote:
I tried using ContactUs, but it will run the code when the contact us form shows. The code need to be ran after the form is submitted.


Add another condition, capturing only when method is POST. ;)
Hace 8 años
wooncherk wrote:

Add another condition, capturing only when method is POST. ;)


I think it is a good idea. I checked how to get the method type online. I didn't get any solutions. Could you give a hint how to get the method type?

Thanks,

Amy
Hace 8 años
Try filterContext.HttpContext.Request.HttpMethod
Hace 8 años
Cool. You are awesome.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.