首页 > 代码库 > mvc 客户端验证

mvc 客户端验证

@model MvcApplication1.Models.ViewClass
@{
ViewBag.Title = "View2";
}
@******引用这两个js实现客户端的验证 ********@
<script src="http://www.mamicode.com/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="http://www.mamicode.com/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>

<hr />

viewdata无法跨控制传值
ViewData:
@ViewData["View1"]
<hr />
TempData可以跨一次控制进行传值
@TempData["View3"]
<h2>View2</h2>

<div >
@Html.ValidationSummary(true)
@using (@Html.BeginForm())
{
<div >
@Html.LabelFor(m=>m .Name)
@Html.EditorFor(m=>m.Name)
@Html.ValidationMessageFor(m=>m .Name)
</div>

<div >
@Html.LabelFor(m=>m.Age)
@Html.EditorFor(m=>m .Age)
@Html.ValidationMessageFor(m=>m .Age)
</div>

<div >
@Html.LabelFor(m=>m .Address)
@Html.EditorFor(m=>m .Address)
@Html.ValidationMessageFor(m=>m .Address)

</div>
<input type ="submit" value="http://www.mamicode.com/提交" />
<div >
<span></span>
</div>
}

</div>