mercredi 18 mai 2016

Slash in the ActionName attribute for MVC

Is it possible to have a slash in the ActionName attribute in ASP MVC?

e.g. I would like a paths

MyController/MyAction1
MyController/MyAction2/A
MyController/MyAction2/B
MyController/MyAction3

The reason for this is it mimics the navigation a user would use. But if I try to add the following to MyController it doesn't work.

[ActionName("MyAction2/A")]
public ActionResults A() {...}

Obviously without the attribute it wouldn't work either.

I've tried changing my RouteConfig.cs to

routes.MapRoute(
    name: "MyController",
    url: "MyController/MyAction2/{action}",
    defaults: new { controller = "MyController", action = "Index" }
);

But this affects all MyController paths. How can I get either a slash in the action name, or have the route config 'override' only come in to play when the action is MyAction2?

Aucun commentaire:

Enregistrer un commentaire