c# - AreaRegistration MapRoutes for Help Docs -
I have an API that is using Web API2 and I am trying to create help docs in a region So that's like the incoming request. ..api / people.help will be the way for the controller of the people and people will see and serve HTML. After refactoring the code, I am struggling with field mapping for root mapping. Previously, I had a route like this:
Public Override Blank Register Array (AreaRegistration Contact Reference) {context.MapRoute (name: "help", url: "{action} .help" Default: new {domain = "help", controller = "default"});
All methods were in the default controller and it used to be working Now, I need a separate controller for each resource (such as people, schedules etc.), but the routes to work can not be found. I appreciate the help, I'm very new to this How do I get each help request to map the controller with the same action name?
No, this is something similar to:
public override register Arraya (Area Registry Contact Reference) {context.MapRoute (name: "help", url: "api / {controller} .help", default: new {domain = "help"}); }
What is the default for the controller's name, in this case, its name will always be default
. Instead, what you are looking for is that when someone pastes routes with your .help
for your controller name, then they are api / help / people
, Which will end a default action (in MVC) for the index.cshtml
or the GET request for the controller (for WebAPI).
Therefore, you want to set the default area to help
as shown above. You also want to set the default action which must be executed on the provided controller.
Update: To answer the question in the comment
For MVC, you are using an action whose name matches the URL of the controller The name will be:
Public class PeopleController: Controller {[HttpGet] // is not strictly necessary, but just want to emphasize that it will be public ActionResult People (//) Do studio in action method}}
The only problem is that your action method for each controller Look-will be different, and so ignorant of the root registration purposes. Therefore, you should only have a default support
action:
Public class PeopleController: Controller {[HttpGet} Public Functionality Help () {// do stuff}}
Then you can have the following route:
Public override registerArea (Area Registry Contact Reference) {reference.MapRoute (name: "help", URL : "API / {controller}. Help", default: New {area = "help", action = "help"}}
You can extend this one step further. And a help in the custom base controller class
method:
public class MyBaseController: Controller {public virtual actionless support () {// default behavior content, if appropriate So} // If you do not have any "default" behavior, then you can create a summary of the following: // Public Essential Action Response Support ();} Public Category PeopleController: MyBaseController {Public Override ActionRes Extra Support (//) What stuff}}
Updates to answer OP's question in comments
So, OP is now saying: "But I want my idea to be the same as my controller. PeopleController: Okay, that should not be a problem MyBaseController // If you are using a Base class {Public Override ActionResult Help {return ViewResult ("People" );}}
Therefore, you may want to have a sequence with any name, but if the name of the scene is different from the name of the action method, A ViewResult
, you have to specify the name of the scene to go back.
fields / {AreaName} / view / {controller} / {VIEWNAME} {vb cs} and here, {viewname}
By default, the name of the action method is considered, but when the above says, MVC does not need to be told explicitly, which tells to return (in the example above, in the above example, Code> People.cshtml < / Code>). HH.
Comments
Post a Comment