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 = "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个字符" })
最新文章
- jQuery2.x源码解析(回调篇)
- 使用PHP的CURL模拟POST采集开了viewstate的asp.net网页数据
- android 开发工具(android studio)
- linux中cat、more、less命令区别详解
- 8 种 NoSQL 数据库系统对比
- C++标准库开发心得
- jOOQ
- FineUI页面级别的参数配置
- MYSQL:基础—存储过程
- 初学Python(十)——列表生成式
- bind 小测试
- Hibernate入门(五)---------事务管理
- PHP7.27: pdf
- RTT(往返时间)和RPC
- 2.1 Visio画图后,粘贴到word白边太宽
- to refactor for refactor
- kudu 存储引擎简析
- Android源码中中一种常见的struct使用方法
- python中递归调用
- supervisor+gunicorn部署python web项目
热门文章
- 170602、防止sql注入(一)
- MVC认识
- | unauthenticated user (1130, ";Host &#39;127.0.0.1&#39; is not allowed to connect to this MySQL server";)
- mongdb ---shard
- SQLAlchemy中scoped_session实现线程安全
- yii2框架2 (二)项目结构
- Mysql EXPLAIN 相关疑问: Using temporary ; Using filesort
- 【python】Python3 循环语句
- 【PHP】善用php-fpm的慢执行日志slow log,分析php性能问题
- 三个小时学会wordpress模板制作