Replies: 26 comments
-
Try this please. public async Task<IActionResult> Create(string id, string menuContentItemId, string? menuItemId){
} |
Beta Was this translation helpful? Give feedback.
-
@Skrypt string? case error compile |
Beta Was this translation helpful? Give feedback.
-
Oh really this doesn't work? |
Beta Was this translation helpful? Give feedback.
-
@Skrypt yes you can try it,i search all of orchardcore code ,there is none routes.MapAreaRoute use three parameters |
Beta Was this translation helpful? Give feedback.
-
hmmm You are right in fact this doesn't work at all sorry mate my error. Though I don't understand why you have this issue. Look at the latest source and this is all working. |
Beta Was this translation helpful? Give feedback.
-
I want to use simple URLs in a unified way ,OrchardCore.xxx and & in Url is too long |
Beta Was this translation helpful? Give feedback.
-
public async Task<IActionResult> Create(string id, string menuContentItemId, string menuItemId = ""){
} |
Beta Was this translation helpful? Give feedback.
-
I can't find this routes.MapAreaRoute anywhere in OC so I presume this is custom code right? |
Beta Was this translation helpful? Give feedback.
-
yes , namespace OrchardCore.Menu
{
public class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDataMigration, Migrations>();
services.AddScoped<IShapeTableProvider, MenuShapes>();
services.AddScoped<IPermissionProvider, Permissions>();
// MenuPart
services.AddScoped<IContentHandler, MenuContentHandler>();
services.AddScoped<IContentPartDisplayDriver, MenuPartDisplayDriver>();
services.AddSingleton<ContentPart, MenuPart>();
services.AddSingleton<ContentPart, MenuItemsListPart>();
// LinkMenuItemPart
services.AddScoped<IContentPartDisplayDriver, LinkMenuItemPartDisplayDriver>();
services.AddSingleton<ContentPart, LinkMenuItemPart>();
services.AddTagHelpers<MenuTagHelper>();
}
public override void Configure(IApplicationBuilder builder, IRouteBuilder routes, IServiceProvider serviceProvider)
{
routes.MapAreaRoute(
name: "SubMenuCreate",
areaName: "OrchardCore.Menu",
template: "SubMenu/Create/{id}/{menuContentItemId}/{menuItemId}",
defaults: new { controller = "Admin", action = "Create" }
);
}
}
} |
Beta Was this translation helpful? Give feedback.
-
By the way it's faster just sending code than sending images. You can use github markdown code : ``` |
Beta Was this translation helpful? Give feedback.
-
OK , but how to fix this problem |
Beta Was this translation helpful? Give feedback.
-
I'm looking at the code to understand which route the controller action uses normally. |
Beta Was this translation helpful? Give feedback.
-
Ok so the Create action of this controller is for adding a menu item to a Menu. But when you click on the "add" button that is on a "menu item" it will pass the current menu item clicked as the "menuItemId" that will be his "parent" to add it under it. So what you are trying to do is use the OrchardCore.Menu module outside OC context I guess. Which is why you need to add the routes.MapAreaRoute() method in your startup. You should not change the controller params to have a default value then. You should just pass the proper menu item id's to the controller action so that it works properly. If you are saying that the action is never getting hit then the issue is with the route declaration. |
Beta Was this translation helpful? Give feedback.
-
Seems to work on my side |
Beta Was this translation helpful? Give feedback.
-
Yes, @jtkech do you know where the routes are added for the menus? Maybe in the abstractions? But here he seems to say that this is not working for him so I'm guessing that he's trying to use the module as a standalone module for something else than OC. |
Beta Was this translation helpful? Give feedback.
-
We previously closed the issue because this is a none issue if we can't repro in OC. Unless @mmdqq sends us repro steps of an issue then this will be tagged as a discussion because it's too vague. |
Beta Was this translation helpful? Give feedback.
-
And I always forget that |
Beta Was this translation helpful? Give feedback.
-
Routes are defined globally in Just copy paste the above |
Beta Was this translation helpful? Give feedback.
-
@jtkech you Url just one parameter,you can try use @Skrypt 's example to add "324234"'s submenu,this way need three parameters |
Beta Was this translation helpful? Give feedback.
-
Okay, the above As i have seen, Okay, i tried this url Then i got this page. |
Beta Was this translation helpful? Give feedback.
-
But if i publish i get a 404 because it doesn't find the specified parent menu |
Beta Was this translation helpful? Give feedback.
-
however i think the problem is MapAreaRoute's template cannot match more than two parameters,but how two fix it? |
Beta Was this translation helpful? Give feedback.
-
I did not get this 404 let me try again. |
Beta Was this translation helpful? Give feedback.
-
Then i tried to add an existing contentItemId as the third parameter, for this i edited the
Then, i got the same above page, and when publishing the new content item has been added, and just under the about item (its parent) and on the left (as a child). Knowing that a content item is a menu with its own items ... Good luck, need to leave. |
Beta Was this translation helpful? Give feedback.
-
Well let's see if at least the controller action will get hit. I will fake the id's. 4js2vph5exx0p4424dfpcjyg42&menuitemid=4p3jz6ezjhba0vqhsxv7cxtkxf That's the actual issue here the route mapping is not working properly. And I get the same 404 error. |
Beta Was this translation helpful? Give feedback.
-
The routes.MapAreaRoute named “SubMenuCreate” didn't work at all.
Beta Was this translation helpful? Give feedback.
All reactions