I have been busy for several months, and I haven't written anything for a long time. Recently, I am a little blank. I went back to my research on ASP. NET MVC RC (MVC RC. The "scaffolding (Scaffold)" function of mvc rc can be said to be a huge addition to the development of mvc rc. However, it seems that there are some regrets in the application to the real development environment: in many cases, we do not want to place Models, Views, and Controllers in the same project. Instead, we want to separate them into different projects and then create a project (such as Views) reference all other project assembly in a unified manner. However, after doing so, the scaffold function in the Controllers project will disappear ".
In the Web (mvc rc) project, we can create a View page using scaffolding in the Web project as follows:
Or create the Controller file:
You can even automatically create or View the View page of the corresponding Action in the Controller file:
However, after the separation of Views and Controllers, they can no longer be used in Controllers (the reason will be described below ). Next we will perform a test.
First, we need to separate the three layers of M, V, and C, for example:
Note that when doing so, you need to reference the following three core assemblies in the Controllers project:
System. Web. Export actions. dll
System. Web. Mvc. dll
System. Web. Routing. dll
And some namespaces referenced in the default Controller. cs file, such:
System. Web
System. Configuration
The following is the separation of M-V-C (M is also to be separated out Because C needs to reference M, and C can not reference V) after running the default interface, it indicates that such separation is successful:
OK. By now, MVC works normally, ...... MVC scaffolding cannot be used in MyMvc. Controllers:
Analyze the cause: When we split the Controller, we created a "Class Library". Of course, a common Class Library cannot use the MVC (Web) scaffolding, so I opened MyMvc. myMvc. web. csproj: Open this file in Notepad (essentially an XML file) and discover something different from other projects:
<ProjectTypeGuids> {603c0e0b-db56-11dc-be95-000d561079b0}; {349c5851-65df-111089384-00065b846f21}; {fae04ec0-301f-11d3-bf4b-00c04f79efbc} </ProjectTypeGuids>
This node uses semicolons to separate three seemingly Guid codes:
{603c0e0b-db56-11dc-be95-000d561079b0}
{349c5851-65df-111089384-00065b846f21}
{Fae04ec0-301f-11d3-bf4b-00c04f79efbc}
I immediately compared MyMvc. Controllers. csproj under MyMvc. Controllers and found that this node was not found. Overjoyed! So I copied the node to the corresponding location of MyMvc. Controllers. csproj. After reloading the project, I found that the scaffold function of MyMvc. Controllers was back!
However, after such a simple addition, we still find some small flaws: The project icon type of MyMvc. Controller in the micrograph is the same as that of the Web ()? Unhappy.
It seems that such direct replication copies the types under the entire MVC Web Application. To avoid unnecessary troubles in the future, it is necessary to change Controllers back to the "class library ", so play the three Guid attention, after the two paired match ({fae04ec0-301f-11d3-bf4b-00c04f79efbc} must be retained) found, as long as the middle of the delete {349c5851-65df-111089384-00065b846f21}, MyMvc. the Controllers project is back to the "class library" status:
So guess {fae04ec0-301f-11d3-bf4b-00c04f79efbc} corresponds to the Web Application project type, and {603c0e0b-db56-11dc-be95-000d561079b0} corresponds to the mvc rc template.
Note:{603c0e0b-db56-11dc-be95-000d561079b0}Corresponding to the mvc rc (v1.0) project code,
If you are usingMVC 2.0(Including the Preview version), the corresponding encoding is: {F85E285D-A4E0-4152-9332-AB1D724D3325}!
If you are usingMVC 3.0(Including Beta and RC versions), the corresponding encoding is: {E53F8FEA-EAE0-44A6-8774-FFD645390401}!
With these operations, the M-V-C structure is detached and in Controllers"Complete"The scaffolding function of mvc rc is retained.
The above"Complete"The reason is that the reservation is too "complete", so that the View page automatically added to the Controller project will be added to the Controller project, rather than the desired MyMvc. view Project ). This is a big problem. If this problem is not solved, scaffolding will become a stumbling block. How can this problem be solved?
See the next article 《IsASP. net mvc rc separation C-V project after adding "scaffolding" function (2)
(The example of this article also provides download in ASP. net mvc rc separation C-V project after adding "scaffold" function (2 .)