HtmlHelper类(续)
Html.TextArea
用于生成<textarea>标签
<%:Html.TextArea("text","Hello<br/>world")%>
输出结果
<textArea cols="20" id="text" name="text" rows="2"> hello
<br/>world </textarea>
<%:Html.TextArea("text","Hello<br/>world",10,80,null)%>
输出结果
<textArea cols="80" id="text" name="text" rows="10"> hello
<br/>world </textarea>
强类型支持
<%:Html.TextAreaFor(m=>m.Description)%>
Html.ValidationMessage
显示ModelState验证结果
public ActionResult Index()
{
var modelstate=new ModelState();
modelstate.Errors.Add("有错");
ModelState["Name"]=modelstate;
return View();
}
View层
<%:Html.ValidationMessage("Name")%>
显示结果
<span class="field-validation-error">有错</span>
<%:Html.ValidationMessage("Name","有些代码出错了")%>
显示结果
<span class="field-validation-error">有些代码出错了</span>
强类型
<%:Html.ValidationMessageFor(m=>m.Name,"出错了")%>
public ActionResult Index()
{
var modelstate=new ModelState();
modelstate.Errors.Add("出错了");
ModelState["Name"]=modelstate;
var modelstate2=new ModelState();
modelstate2.Errors.Add("又错了");
ModelState["age"]=modelstate2;
return View();
}
View层:<%:Html.ValidationSummary()%>
返回结果<ul class="validation-summary-errors">
<li>出错了</li><li>又错了</li></ul>
HTML 模板
支持自定义模板
2011-4-15 22:54 danny
Html.TextArea
用于生成<textarea>标签
<%:Html.TextArea("text","Hello<br/>world")%>
输出结果
<textArea cols="20" id="text" name="text" rows="2"> hello
<br/>world </textarea>
<%:Html.TextArea("text","Hello<br/>world",10,80,null)%>
输出结果
<textArea cols="80" id="text" name="text" rows="10"> hello
<br/>world </textarea>
强类型支持
<%:Html.TextAreaFor(m=>m.Description)%>
Html.ValidationMessage
显示ModelState验证结果
public ActionResult Index()
{
var modelstate=new ModelState();
modelstate.Errors.Add("有错");
ModelState["Name"]=modelstate;
return View();
}
View层
<%:Html.ValidationMessage("Name")%>
显示结果
<span class="field-validation-error">有错</span>
<%:Html.ValidationMessage("Name","有些代码出错了")%>
显示结果
<span class="field-validation-error">有些代码出错了</span>
强类型
<%:Html.ValidationMessageFor(m=>m.Name,"出错了")%>
public ActionResult Index()
{
var modelstate=new ModelState();
modelstate.Errors.Add("出错了");
ModelState["Name"]=modelstate;
var modelstate2=new ModelState();
modelstate2.Errors.Add("又错了");
ModelState["age"]=modelstate2;
return View();
}
View层:<%:Html.ValidationSummary()%>
返回结果<ul class="validation-summary-errors">
<li>出错了</li><li>又错了</li></ul>
HTML 模板
支持自定义模板
2011-4-15 22:54 danny