C# 如何在MVC3中取消備用控制器的選擇

來源:互聯網
上載者:User

C#的MVC尋找對應的控制器首先是尋找當前域的

如果找不到就會尋找備用的..

但是有些時候我們是不想他去尋找備用的控制器.

這裡就涉及到了一個DataToken

複製代碼 代碼如下: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" }
);

我第一次是使用new string來區分,可惜他還是會去尋找.我翻閱了一些資料之後

發現如果要取消備用控制器需要這麼寫

複製代碼 代碼如下: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;

這樣我們就取消的使用備用控制器的操作了.

另外備份一下MVC的一些公約複製代碼 代碼如下:protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//db.ContextOptions.LazyLoadingEnabled = false;
//db.ContextOptions.ProxyCreationEnabled = false;
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();//移除複數表名的契約
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
base.OnModelCreating(modelBuilder);
/*

可以刪除的公約有:
Namespace:System.Data.Entity.ModelConfiguration.Conventions.Edm
• AssociationInverseDiscoveryConvention
尋找導航上互相引用的類的屬性,並將它們配置為逆屬性的相同的關係。
• ComplexTypeDiscoveryConvention
尋找有沒有主鍵的類型,並將它們配置為複雜類型。
• DeclaredPropertyOrderingConvention
確保每個實體的主要關鍵屬性優先於其他屬性。
• ForeignKeyAssociationMultiplicityConvention
配置是必需的還是可選的關係基於為空白性外鍵屬性,如果包含在類定義中。
• IdKeyDiscoveryConvention
尋找名為 Id 或 <TypeName> Id 的屬性,並將他們配置作為主鍵。
• NavigationPropertyNameForeignKeyDiscoveryConvention
使用外鍵關係,使用 <NavigationProperty> <PrimaryKeyProperty> 模式作為屬性的外觀。
• OneToManyCascadeDeleteConvention
交換器上層疊刪除,所需的關係。
• OneToOneConstraintIntroductionConvention
將配置為一個: 一個關係的外鍵的主鍵。
• PluralizingEntitySetNameConvention
配置為多元化的類型名稱的實體資料模型中的實體集的名稱。
• PrimaryKeyNameForeignKeyDiscoveryConvention
使用外鍵關係,使用 <PrimaryKeyProperty> 模式作為屬性的外觀。
• PropertyMaxLengthConvention
配置所有的字串和位元組 [] 屬性,預設情況下具有最大長度。
• StoreGeneratedIdentityKeyConvention
配置預設情況下將標識所有整數的主鍵。
• TypeNameForeignKeyDiscoveryConvention
使用外鍵關係,使用 <PrincipalTypeName> <PrimaryKeyProperty> 模式作為屬性的外觀。

*/}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.