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


    */
    }

  • 相关阅读:
    经验总结
    C#小技巧收集总结
    随笔
    看盘做短线的10种方法(转)
    dvbbs 7.1版块图标感应渐变效果 From www.jfeng.cn
    动网的个人文集、个人精华
    dvbbs 文件Dv_News.asp 的外部调用
    动网论坛多系统整合Api接口程序 PDO通行接口开发人员参考规范1.0
    动网首页登陆入口调用
    ASP 有关整合动网论坛的问题
  • 原文地址:https://www.cnblogs.com/mota/p/3064067.html
Copyright © 2011-2022 走看看