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


    */
    }

  • 相关阅读:
    chapter1 Qt入门
    base64加密解密
    vue+CryptoJS+cookie实现保存账号密码
    js计时器
    Elenent ui中的表单校验规则、自定义校验规则、预验证功能
    js获取文件后缀
    js中如何将有字符串转换为数组,或将数组转换为字符串
    vue-router
    Vue项目纯前端导出word文档
    async/await
  • 原文地址:https://www.cnblogs.com/mota/p/3064067.html
Copyright © 2020-2023  润新知