zoukankan      html  css  js  c++  java
  • MVC自定义视图

    编写自定义模板,以单选按钮为例
     
    1.在Shared新建模板视图(文件夹名必须为EditorTemplates)
     
     
     
    2.编写模板代码
     
    @model bool
     
    <table>
    <tr>
    <td>@Html.RadioButton("sex", true, Model)男</td>
    <td>@Html.RadioButton("sex", false, !Model)女</td>
    </tr>
    </table>
     
    3.定义模型,
    当模板名为类型名时,默认都使用
    namespace MVCDiary.Models
    {
    public class Person
    {
    [DisplayName("姓名:")]
    public string Name { get; set; }
    [DisplayName("性别")]
    public bool Sex { get; set; }
    }
    }
     
    当使用UIHint选定,使用指定模板(DisplayName取别名)
     
    namespace MVCDiary.Models
    {
    public class Person
    {
    [DisplayName("姓名:")]
    public string Name { get; set; }
    [DisplayName("性别")]
    [UIHint("TestBoolean")]
    public bool Sex { get; set; }
    }
    }
    4.调用
    @using MVCDiary.Models
    @{
    Layout = null;
    }
    @model Person
    <!DOCTYPE html>
     
    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    </head>
    <body>
    11111
    @using (Html.BeginForm())
    {
    @Html.EditorForModel();
    }
    </body>
    </html>
     
     
     

  • 相关阅读:
    HDU 4508
    HDU 4503
    HDU 4532
    HDU 4544
    HDU 3167 KMP
    HDU 4542
    HDU 4528
    【70】自然语言处理与词嵌入
    【69】循环神经网络
    【68】一维和三维卷积
  • 原文地址:https://www.cnblogs.com/xieyang07/p/9853389.html
Copyright © 2011-2022 走看看