ASP.NET Convention Based Naming
Could someone ex开发者_开发问答plain ASP.NET Convention Based Naming and provide some examples if possible please
Convention-based naming is essentially a way to reduce the amount of explicit code you have to write by defining a set of convention mappings so that, for example, pages whose names match a certain format will be automatically looked for within a certain directory.
There's an article here which has some examples (have a search for 'Convention-based naming and the \Views directory structure') and another from the same series here.
There's another, more concise example here: ASP.NET MVC: When convention really matters.
In that example, calling return View("NotFound");
from the DinnersController
class will automatically look for a View called NotFound
in the \Views\Dinners\
directory, without you needing to explicitly define that directory structure when you call View()
.
The convention in this instance determines the location of the View
based on the name of the Controller
.
Naming Guidelines
General Naming Conventions
Guidelines for Names
All primary sources from Microsoft.
I can't think of any ASP.NET examples, but ASP.NET MVC certainly uses conventions. One example, is that a request to \Report\View
is automatically mapped to a controller called ReportController
containing a method called View()
. There's no need to do any other wiring - just ending your class name with Controller
is enough.
精彩评论