Excerpt from the Book Pro ASP. NET MVC3 Framework:
I. disadvantages of Web Form
1. view state weight: The data stored in view state is transferred back and forth in each HTTP request, and the data volume can be large, resulting in slow response time and increased bandwidth requirements.
2. The page lifecycle is quite complex.
3.html access is worse. server controls are eventually presented in the form of pure HTML, but are often not presented in the form of WEB standards. As a result, CSS cannot be well utilized, the server control is rendered to generate unpredictable and complex IDs, making it difficult to access
4. Close architecture is not suitable for unit testing
Ii. DI (dependency inject) dependency Injection
Reduce the Coupling Degree of components. The container used is Ninject.
Public interface IA
{
Void fun_A (String str );
}
Public class A: IA
{
Public void fun_A (String str)
{
Console. WriteLine ("{0}", str );
}
}
Public interface IB
{
Void fun_ B ();
}
Public class B: IB
{
Private IA ia;
Public B (IA IgA)
{
Ia = fa;
}
Public void fun_ B ()
{
Ia. fun_A ("test in interface IA ");
}
}
Public class C
{
Private IB ib;
Public C (IB ibb)
{
Ib = ibb;
}
Public void GoTest ()
{
Ib. fun_ B ();
}
}
Class Program
{
Static void Main (string [] args)
{
IKernel kernel = new StandardKernel ();
Kernel. Bind <IB> (). To <B> ();
Kernel. Bind <IA> (). To <A> ();
IB B = kernel. Get <IB> ();
C cc = new C (B );
Cc. GoTest ();
Console. ReadKey ();
}
}
// Class C depends on interface IB, and Class B that implements IB depends on interface IA. It can also be said that class C depends on interface IB, and interface IB depends on IA, in this way, a dependency chain is formed. The DI container can be used to automatically create instances of implementation classes for the interfaces that depend on each other. [interface-Oriented Programming]
// After the DI container is used, it automatically clears the chain, creates an implementation class instance, and passes it to the corresponding constructor, also called constructor injection]
// There are three methods for dependency Injection: A. Constructor Injection B. Setter Injection C. Interface Injection
3. Layout
If you do not want to reference the master page, you must @ {Layout = null ;}
If this is not specified, ViewStart. cshtml is referenced as the master by default, while ViewStart. cshtml references _ Layout. cshtml,
If not specified, _ Layout. cshtml is referenced as the master.
Iv. Html. RenderPartial and Html. RenderAction
// Both methods are used to embed user controls on the interface.
(1) Html. RenderPartial ("LogOnUserControl ");
// LogOnUserControl is a partial view name, which defines a user control in this view. This view must be placed in the same directory of the caller or in View/Shared. We can see that this method depends on a partial view.
(2) Html. RenderAction
// From the method name, we can see that this method depends on Action [call the View corresponding to an Action], for example:
Html. RenderAction ("Menu", "Nav ");
// Menu is the Action name. The View corresponding to Menu is called, and Nav is the Controller name of the Action.