zoukankan      html  css  js  c++  java
  • UIHint属性的用途是什么?

    MVC中UIHint属性的用途。 我们为什么需要这个。 以及何时和如何使用?

    UIHintAttribute指定动态数据用来显示数据字段的模板或用户控件。

    这是UIHintAttribute的MSDN描述。它首先针对动态数据应用程序引入,并且ASP.NET MVC也对其进行了修改。

    如果使用UIHint属性为属性添加注释并在视图中使用EditorForDisplayFor内部视图,则ASP.NET MVC框架将查找您通过指定的指定模板UIHintAttribute它查找的目录是:

    对于EditorFor

    ~/Views/Shared/EditorTemplates

    ~/Views/Controller_Name/EditorTemplates

    对于DisplayFor

    ~/Views/Shared/DisplayTemplates

    ~/Views/Controller_Name/DisplayTemplates

    如果您在某个区域,则它也适用于您所在的区域,就像上面一样。

    这是用法示例:

    public class Person { 
    
        [UIHint("Poo")]
        public string Name { get; set; }
    }

    MVC框架会寻找名为局部视图poo指定的目录下,如果你尝试输出的模型属性与EditorForDisplayFor象下面这样:

    @model MyApp.Models.Person
    
    <h2>My Person</h2>
    
    @Html.DisplayFor(m => m.Name)

    如何创建“ Poo”显示模板?

    poo.cshtml的内容:
    @model string 
    @{ <span class='poo'>@Model</span> }

    Name属性是string

    默认情况下,@Html.EditorFor(m => m.Name)查找string编辑器。

    Views/Shared/EditorTemplates/Name.cshtml

    例如,要插入自定义的局部视图编辑器

    有2个选项:

    @Html.EditorFor(m => m.Name, "Name")

    [UIHint("Name")] 

    public string Name { get; set; }

    来自:https://stackoverflow.com/questions/8196372/what-is-use-of-uihint-attribute-in-mvc

  • 相关阅读:
    parted分区
    gitlab的还原
    hadoop2.7.3+spark2.0.1+scala2.11.8集群部署
    Daily record-September
    三次握手和四次挥手【转】
    “梅西式”程序员 【转】
    C++解析十-数据封装
    客户端、服务器代码实例
    网络整理
    C++解析九-数据抽象
  • 原文地址:https://www.cnblogs.com/djd66/p/14821840.html
Copyright © 2011-2022 走看看