Admin plugin route

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 anni tempo fa
Geralt wrote:
So I found another way to use the Html.DeleteConfirmation extension without adding a new map route just for a single delete call (as noted in the post right above this one)

From within my plugin, I just made a new 3 parameter DeleteConfirmation as noted:
public static MvcHtmlString DeleteConfirmation<T>(this HtmlHelper<T> helper, string actionName, string controllerName, string buttonsSelector = null) where T : BaseNopEntityModel
This way I can use a 5 part admin url.
@Html.DeleteConfirmation("Delete", "Plugin/Dealer/Admin", "dealer-delete")
And it will resolve as:

/Admin/Plugin/Dealer/Admin/Delete/#

Still I'm thinking, there has to be easier way to do this, and I'm just missing something.


Hi Geralt,

You mentioned you created a new 3 parameter DeleteConfirmation extension. Do you have the code for it? I've come up against exactly the same problem!

Thanks alot

Al
11 anni tempo fa
Hi Higgsy,

First off the plugin I was developing at the time and talking about here was for nop v2.20.

So what I did was create a new HtmlExtensions.cs file inside my plugin. In that class I copied the original MvcHtmlString DeleteConfirmation<T> over, and made the following 3 changes to it.

Instead of:

public static MvcHtmlString DeleteConfirmation<T>(this HtmlHelper<T> helper, string actionName, string buttonsSelector = null) where T : BaseNopEntityModel

I have:

public static MvcHtmlString DeleteConfirmation<T>(this HtmlHelper<T> helper, string actionName, string controllerName, string buttonsSelector = null) where T : BaseNopEntityModel

Instead of:

            if (String.IsNullOrEmpty(actionName))
                actionName = "Delete";

I have:

            if (String.IsNullOrEmpty(actionName))
                actionName = "Delete";
            if (String.IsNullOrEmpty(controllerName))
                controllerName = helper.ViewContext.RouteData.GetRequiredString("controller");

Then instead of:

ControllerName = helper.ViewContext.RouteData.GetRequiredString("controller"),

I have:

ControllerName = controllerName,


Then I was able to call it with @Html.DeleteConfirmation("Delete", "Plugin/Dealer/Admin", "dealer-delete"), passing in the extra controller name that got it to work.
11 anni tempo fa
Perfect, thanks so much!

Al
9 anni tempo fa
Hi all.
Do you have decision for version 3.4 or high?
9 anni tempo fa
Hi Guys,
As per above discussions, I rewrite my route to

I am building a plugin in 3.50.
I've added a new menu item, which appends under Plugins menu item by default.
var SubMenuItem = new SiteMapNode() 
{
        Title = "Manage",
        ControllerName = "CustomManager",
        ActionName = "List",
        Visible = true,
        RouteValues = new RouteValueDictionary() { { "area", null } },
};
and the routing defined is as
routes.MapRoute("Plugin.Custom.Manager.List",
       "Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

also tried routing with many ways like

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/Admin/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

I've created the List.cshtml under Views-> CustomManager -> List.cshtml & the controller is named as CustomManagerController.cs

I also added in  List.cshtml
@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}

But still the url in the browser's generates as http://localhost:15536/CustomManager/List
instead http://localhost:15536/Admin/CustomManager/List
and also once I select my menu item, then some of the link items lose the Admin/ prefix like 'Clear cache', 'Restart application'

Please help me, what I've missed!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.