Issue in setting RouteProvider Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 года назад
Dear Sir/Madam,
I have a problem with routes in plugin (NopCommerce 4.30).  I have a method List() in Controller CustomController.cs, and in my configure.cshtml, I want to call method List() to load data. However, I can not set route to call method List. Please help me!
Here are the snippet code belows
#Configure.cshtml
....
<div class="panel panel-default">
  <div class="panel-body">
    @await Html.PartialAsync("Table", new DataTablesModel
       {
         Name = "grid",
         UrlRead = new DataUrl("List", "Custom",null),
         Paging = false,
         ColumnCollection = new List<ColumnProperty>
         {
        ...
         }
       })
  </div>
</div>
#CustomControler
namespace Nop.Plugin.Widgets.Custom.Controllers
{
    [Area(AreaNames.Admin)]
    [AuthorizeAdmin]
    [AutoValidateAntiforgeryToken]
    public class CustomController : BasePluginController
    {
    public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets))
                return AccessDeniedView();
      ...
    }
    [HttpPost]
        public IActionResult Configure(CustomModel model)
        {
            if (!ModelState.IsValid)
            {
                return Configure();
            }
      ...
    }
    [HttpPost]
        public virtual IActionResult List(CustomSearchModel searchModel)
        {
      ...
      return json(model);
    }
  }
}
#RouteProvider
namespace Nop.Plugin.Widgets.Custom.Infrastructure
{
  public class RouteProvider : IRouteProvider
  {
    public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
    {
      //add route for the access token callback
      endpointRouteBuilder.MapControllerRoute("Plugin.Widgets.Custom.Configure", "Plugins/Custom/Configure",
        new { controller = "Custom", action = "Configure", area = AreaNames.Admin });
    }
    public int Priority => 0;
  }
}
#_ViewImports.cshtml
@inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage<TModel>
@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject Nop.Services.Stores.IStoreService storeService
@inject IWorkContext workContext
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Nop.Web.Framework

@using Microsoft.AspNetCore.Mvc.ViewFeatures
@using Microsoft.AspNetCore.Routing
@using Nop.Core
@using Nop.Core.Domain.Common
@using Nop.Core.Infrastructure
@using Nop.Plugin.Widgets.Custom
@using Nop.Plugin.Widgets.Custom.Models
@using Nop.Services.Events
@using Nop.Web.Framework
@using Nop.Web.Framework.Models
@using Nop.Web.Framework.Events
@using Nop.Web.Framework.Extensions
@using Nop.Web.Framework.Infrastructure
@using Nop.Web.Framework.Models.DataTables
@using Nop.Web.Framework.Security.Captcha
@using Nop.Web.Framework.Security.Honeypot
@using Nop.Web.Framework.Themes
@using Nop.Web.Framework.UI
3 года назад
huynhhoc wrote:

    @await Html.PartialAsync("Table", new DataTablesModel
       {
         Name = "grid",
         UrlRead = new DataUrl("List", "Custom",null),


You dont need a route to call the List function

In my CustomController I have

        [AuthorizeAdmin]
        [Area(AreaNames.Admin)]
        public virtual IActionResult List(SearchModel searchModel)
        {
            //prepare model
            var model = PrepareListModel(searchModel);

            return Json(model);
        }

Plus up the top of your controller you have
    [Area(AreaNames.Admin)]
    [AuthorizeAdmin]
    [AutoValidateAntiforgeryToken]
    public class CustomController : BasePluginController

I dont have the attributes
I just have
    public class CustomController : BasePluginController
3 года назад
Yidna wrote:

    @await Html.PartialAsync("Table", new DataTablesModel
       {
         Name = "grid",
         UrlRead = new DataUrl("List", "Custom",null),


You dont need a route to call the List function

In my CustomController I have

        [AuthorizeAdmin]
        [Area(AreaNames.Admin)]
        public virtual IActionResult List(SearchModel searchModel)
        {
            //prepare model
            var model = PrepareListModel(searchModel);

            return Json(model);
        }

Plus up the top of your controller you have
    [Area(AreaNames.Admin)]
    [AuthorizeAdmin]
    [AutoValidateAntiforgeryToken]
    public class CustomController : BasePluginController

I dont have the attributes
I just have
    public class CustomController : BasePluginController


Dear Yidna,
I did as you guide, but I have the same issue, cannot call the List() function :(.
Regards,
3 года назад
huynhhoc wrote:

    @await Html.PartialAsync("Table", new DataTablesModel
       {
         Name = "grid",
         UrlRead = new DataUrl("List", "Custom",null),


You dont need a route to call the List function

In my CustomController I have

        [AuthorizeAdmin]
        [Area(AreaNames.Admin)]
        public virtual IActionResult List(SearchModel searchModel)
        {
            //prepare model
            var model = PrepareListModel(searchModel);

            return Json(model);
        }

Plus up the top of your controller you have
    [Area(AreaNames.Admin)]
    [AuthorizeAdmin]
    [AutoValidateAntiforgeryToken]
    public class CustomController : BasePluginController

I dont have the attributes
I just have
    public class CustomController : BasePluginController

Dear Yidna,
I did as you guide, but I have the same issue, cannot call the List() function :(.
Regards,


Hi, this issue has been fixed after I remove the link "<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>" out of configure.cshtml.
Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.