//生成表单

@{ 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 = "width: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 = "密码不能为空")]

, MinimumLength = , ErrorMessage = "密码必须在{2} 和{1}之间")]

public string UserPassword { get; set; }

类似的有

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

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

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

[Range(, , 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 = "width:200px; height:100px;" })

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

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

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

最新文章

  1. jQuery2.x源码解析(回调篇)
  2. 使用PHP的CURL模拟POST采集开了viewstate的asp.net网页数据
  3. android 开发工具(android studio)
  4. linux中cat、more、less命令区别详解
  5. 8 种 NoSQL 数据库系统对比
  6. C++标准库开发心得
  7. jOOQ
  8. FineUI页面级别的参数配置
  9. MYSQL:基础—存储过程
  10. 初学Python(十)——列表生成式
  11. bind 小测试
  12. Hibernate入门(五)---------事务管理
  13. PHP7.27: pdf
  14. RTT(往返时间)和RPC
  15. 2.1 Visio画图后,粘贴到word白边太宽
  16. to refactor for refactor
  17. kudu 存储引擎简析
  18. Android源码中中一种常见的struct使用方法
  19. python中递归调用
  20. supervisor+gunicorn部署python web项目

热门文章

  1. 170602、防止sql注入(一)
  2. MVC认识
  3. | unauthenticated user (1130, &quot;Host &#39;127.0.0.1&#39; is not allowed to connect to this MySQL server&quot;)
  4. mongdb ---shard
  5. SQLAlchemy中scoped_session实现线程安全
  6. yii2框架2 (二)项目结构
  7. Mysql EXPLAIN 相关疑问: Using temporary ; Using filesort
  8. 【python】Python3 循环语句
  9. 【PHP】善用php-fpm的慢执行日志slow log,分析php性能问题
  10. 三个小时学会wordpress模板制作