C # Implementation of MVC in Engineering

Source: Internet
Author: User

1. Put the collection in another example.

Add another class classlibrary1 to define all collections

2. Reference this type of metadata in webmvc example.

For normal use, the following definitions must be made in the global. asax file in this example.

       Public   Static   Void Registerroutes (routecollection routes)
{

Routes. ignoreroute ( " {Resource}. axd/{* pathinfo} " );

Routes. maproute (
" Default " , // Route name
" {Controller}/{action}/{ID} " , // URL with Parameters
New {Controller = " Home " , Action = " Index " , Id = urlparameter. optional} // Parameter defaults
, New String [] { " Classlibrary1 " }
);

}

The namespace of the collection to be added here.

3. In order to use a different file to upload a facial file, follow these steps:

3.1 create a file named viewtest, and then define the same object as the default view file. If you do not want to create a shard file, you can use.

3.2 Add a web. config file. The same as the default view. Otherwise, the response is abnormal.

3.3 Add the _ viewstart. cshtml file. The same as the default view.

3.4 is mixed in my memory.

3.5 then, in the global. asax file, make the following definitions:

      Public   Static   Void Registerroutes (routecollection routes)
{
Razorviewengine razor = New Razorviewengine ();
Razor. viewlocationformats = New String [] {
" ~ /Viewtest/{1}/{0}. cshtml " ,
" ~ /Viewtest/{1}/{0}. vbhtml " ,
" ~ /Views/shared/{0}. cshtml " ,
" ~ /Views/shared/{0}. vbhtml " };

Viewengines. Engines. Clear ();
Viewengines. Engines. Add (razor );
Routes. ignoreroute ( " {Resource}. axd/{* pathinfo} " );

Routes. maproute (
" Default " , // Route name
" {Controller}/{action}/{ID} " , // URL with Parameters
New {Controller = " Home " , Action = " Index " , Id = urlparameter. optional} // Parameter defaults
, New String [] { " Classlibrary1 " }
);

}

In response to the above token statement:

Define a razorviewengine, and then redefine viewlocationformats. Tell the view where to search.

It's very simple.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.