zoukankan      html  css  js  c++  java
  • C#MVC中@HTML中的方法

    //生成表单

    @{ Html.BeginForm("Index", "Simple", FormMethod.Post, new { id = "myForm" }); }

    @*表单内容*@

    @{ Html.EndForm();}

    或者

    @using (Html.BeginForm("AccountTypeForm", "Account", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {

    @*表单内容*@

    }

    //生成复选框

     @Html.CheckBox("checkBox",new { id="myCheckBox" })

    //生成下拉列表框

    @{ var dropList = new List<SelectListItem>(); 

               for (int i = 0; i < 5; i++) 

               { 

                   var dropItem = new SelectListItem(); 

                   dropItem.Value = i.ToString(); 

                   dropItem.Text = i.ToString(); 

                   dropList.Add(dropItem); 

               } 

          }

    @Html.DropDownList("myList", dropList, new { style = "100px;" })

    //生成超链接

    @Html.ActionLink(" >> 返回列表", "AccountTypeList")

    //生成隐藏文本

     @Html.HiddenFor(model => model.ID)

    //显示错误的控件

    @Html.ValidationSummary(true)

    @*当后台if (ModelState.IsValid)失败后,错误信息就会显示到 @Html.ValidationSummary()*@

    @*当前后台验证都通过,但某些逻辑验证没有通过,比如用记名密码错误的,可以手工添加错误信息,
    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); 这个也会显示到@Html.ValidationSummary()*@

    //根据后台定义添加前台js验证的控件

    @Html.ValidationMessageFor(model => model.UserPassword)

    @*

    [Display(Name="password")]

    [DataType(DataType.Password)] 

    [Required(AllowEmptyStrings = false, ErrorMessage = "密码不能为空")] 

    [StringLength(60, MinimumLength = 20, ErrorMessage = "密码必须在{2} 和{1}之间")] 

    public string UserPassword { get; set; }

    类似的有

    [StringLength(20, MinimumLength = 6, ErrorMessage = "用户名不能大于{2} 且要小于{1}")]

    [Compare("Email", ErrorMessage = "邮箱要相同")]

    [RegularExpression(@"d{17}[d|x]|d{15}", ErrorMessage = "身份证号码格式错误")]

    [Range(10, 100, ErrorMessage = "年龄不能大于{2} 不能小于{1}")]

    [Required(ErrorMessage = "金额不能为空")] 

    [Range(typeof(decimal), "20.0", "30.0", ErrorMessage = "金额在{1}和{2}之间")]

    *@

    //文本

     @Html.LabelFor(model => model.AccountDescription)

    //常用控件

    @Html.TextAreaFor(model => model.AccountDescription, new { @style = "200px; height:100px;" })

    @Html.TextBoxFor(model => model.AccountName, new { @style = "200px;" })

    @Html.EditorFor(model => model.UserPassword)

    @Html.PasswordFor(m => m.PromoterPwd, new { @class = "input_txt", dataType = "LimitB", min = "6", max = "20", msg = "密码为6到20个字符" })

  • 相关阅读:
    解决 搭建Jekins过程中 启动Tomcat的java.net.UnknownHostException异常
    射手和农场主
    java 和 JS(javaScript)中的反斜杠正则转义
    分享修改密码的SharePoint Web part: ITaCS Change Password web part
    分享微软官方Demo用的SharePoint 2010, Exchange 2010, Lync 2010虚拟机
    Office 365 的公共网站的一些限制及解决的办法
    SharePoint 2013 关闭 customErrors
    安装 KB2844286 导致SharePoint 2010 XSLT web part 显示出现错误
    安装Office Web Apps Server 2013 – KB2592525安装失败
    如何将hyper-v虚拟机转换成vmware的虚拟机- 转换SharePoint 2010 Information Worker Demonstration and Evaluation Virtual Machine (SP1)
  • 原文地址:https://www.cnblogs.com/wfy680/p/12213292.html
Copyright © 2011-2022 走看看