How malleable are the conventions in ASP.NET MVC? -


Specifically, the name of a controller class should have a controller suffix, and you change it If you want you to structure the folder in your project without breaking things?

Is there any other conference that can be overridden, and how?

Most conventions are made abusive, provided you know how the structure is running. To deal with the biggest conventions:

  1. "Admin" / {action} / "Magic Search

    Li>

The way you create it is associated with an example. By default, a MvcRouteHandler object is used when dealing with incoming requests, as mentioned here. MvcHandler's ProcessRequest looks like:

  Protected Virtual Virtual Zero ProcessRequest (HttpContextBase HttpContext) {this.AddVersionHeader (HttpContext); String required string = this.RequestContext.RouteData.GetRequiredString ("controller"); IControllerFactory Controller Factory = this.ControllerBuilder.GetControllerFactory (); ICController Controller = ControllerFeature Composition Controller (this.RequestContext, Required string); If (Controller == Faucet) {New InvalidOperationException Throw (String.Format (CultureInfo.CurrentUICulture, MvcResources.ControllerBuilder_FactoryReturnedNull, New Object [] {controllerFactory.GetType (), requiredString})); } {Try Controller. Exquisite (this.RequestContext); } Finally {Controller Factory.ReleaseController (Controller); }}  

Look at the hardcod string "controller" is okay, you can replace this handler for any route if you want to code your own controller-find logic Are there. Just do it:

  route. Add ("Picture Path", new route ("Graphics / {filename}", New ImageRouteHandler ()));  

Now when the path is matched, then he can show his logic, and whatever you can, please. Incidentally, the reflection that is used to find the XXXXController class with the "controller" suffix is ​​part of the defaultControllerFactory object, applied in the handler above, and this factory has changed.

Therefore, choosing a controller is a conference that is overlapping. When you see " return () " by any controller method, what does it look like for the scenes? Well the creator for is the WebFormViewEngine , the default visual engine of the framework:

  public WebFormViewEngine () {base.MasterLocationFormats = new string [] {"~ / view / {1} / {0} .master "," ~ / scene / share / {0} .master "}; Base.ViewLocationFormats = New string [] {"~ / view / {1} / {0} .aspx", "~ / view / {1} / {0} .ascx" "~ / view / share / {0} .aspx "," ~ / visible / share / {0} .ascx "}; Base.PartialViewLocationFormats = base.ViewLocationFormats; }  

If you do not like the conference to view in the controller directory, then share - WebFormViewEngine (or) and with this clap you can easily expand Is in your global.asax:

  see engine. Engine.ed (new MyViewEngine ());  

One of the wonderful things about the MVC framework is that it is actually how easy it is. You can replace almost any part with your own logic - and to see that all the codes made by them are available.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -