C # Remove the alternative controller from mvc3

Source: Internet
Author: User

C # The MVC search for the corresponding controller first looks for the current domain

If you cannot find it, you will find an alternative ..

But sometimes we don't want him to look for a Slave controller.

A datatoken is involved here.

Routes. maproute (
"Default", // route name
"{Controller}/{action}/{ID}", // URL with Parameters
New {controller = "home", Action = "Index", id = urlparameter. optional}, // parameter defaults
New String [] {"Reader. controllers "}
);

For the first time, I used new string to differentiate them. Unfortunately, he will still search for them. After reading some documents

If you want to cancel the backup controller, you need to write it like this.

Routes. maproute (
"Default", // route name
"{Controller}/{action}/{ID}", // URL with Parameters
New {controller = "home", Action = "Index", id = urlparameter. optional}, // parameter defaults
New String [] {"Reader. controllers "}
). Datatokens ["usenamespacefallback"] = false;

In this way, the Standby controller operation is canceled.

 

 

Back up some MVC conventions.

Protected override void onmodelcreating (dbmodelbuilder modelbuilder)
{
// DB. contextoptions. lazyloadingenabled = false;
// DB. contextoptions. proxycreationenabled = false;
Modelbuilder. Conventions. Remove <pluralizingtablenameconvention> (); // remove the contract with the complex table name
Modelbuilder. Conventions. Remove <includemetadataconvention> ();
Base. onmodelcreating (modelbuilder );
/*

The following conventions can be deleted:
Namespace: system. Data. entity. modelconfiguration. Conventions. EDM
• Associationinversediscoveryconvention
Search for the attributes of the classes referenced in the navigation and configure them as the same relationship of the inverse attributes.
• Complextypediscoveryconvention
Find the types with or without primary keys and configure them as complex types.
• Declaredpropertyorderingconvention
Ensure that the primary key attributes of each object take precedence over other attributes.
• Foreignkeyassociationmultiplicityconvention
Whether the configuration is required or optional is based on the null foreign key attribute, if included in the class definition.
• Idkeydiscoveryconvention
Search for the attributes named ID or <typename> ID and configure them as the primary key.
• Navigationpropertynameforeignkeydiscoveryconvention
Use the foreign key relationship and the <navigationproperty> <primarykeyproperty> mode as the attribute appearance.
• Onetomanycascadedeleteconvention
The relationship required for the switch to be deleted.
• Onetooneconstraintintroductionconvention
It is configured as a primary key for a foreign key of a link.
• Pluralizingentitysetnameconvention
Name of the entity set in the object data model configured as a diverse type name.
• Primarykeynameforeignkeydiscoveryconvention
Use the foreign key relationship and the <primarykeyproperty> mode as the attribute appearance.
• Propertymaxlengthconvention
Configure all the string and byte [] attributes, with the maximum length by default.
• Storegeneratedidentitykeyconvention
By default, the primary keys of All integers are identified.
• Typenameforeignkeydiscoveryconvention
Use the <principaltypename> <primarykeyproperty> mode as the appearance of the property.

*/
}

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.