zoukankan      html  css  js  c++  java
  • C# MVC3中取消备用控制器的选择

    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> 模式作为属性的外观。


    */
    }

  • 相关阅读:
    第六十篇、音视频采集硬编码(H264+ACC)
    第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法
    第五十九篇、OC录制小视频
    第五十八篇、iOS 微信聊天发送小视频的秘密
    第五十七篇、AVAssetReader和AVAssetWrite 对视频进行编码
    第五十六篇、OC打开本地和网络上的word、ppt、excel、text等文件
    Objective-C 编码建议
    在block中使用self
    纯代码TableView自适应高度(很老的使用方法)
    iOS应用架构谈 网络层设计方案
  • 原文地址:https://www.cnblogs.com/mota/p/3064067.html
Copyright © 2011-2022 走看看