<appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="PreserveLoginUrl" value="true" /> <add key="ClientValidationEnabled" value="true" /> 开启验证 <add key="UnobtrusiveJavaScriptEnabled" value="true" /> <add key="RouteDebugger:Enabled" value="true"/> 路由 </appSettings>
关于配置
@model P01MVCRoute.Models.Student 强类型 @{ ViewBag.Title = "Add"; } <h2>Add</h2> @using (Html.BeginForm("Add", "Home", FormMethod.Post)) { <table id="tbData"> <tr> <td>@Html.LabelFor(s => s.Name):</td> <td> @*@Html.TextBoxFor(s=>s.Name)*@ @Html.EditorFor(s => s.Name) @Html.ValidationMessageFor(s => s.Name) 验证信息 </td> </tr> <tr> <td>@Html.LabelFor(s=>s.CId):</td> <td> @*@Html.DropDownListFor(s=>s.CId,ViewBag.selList as IEnumerable<SelectListItem>)*@ @*@Html.DropDownList("CId",ViewBag.selList as IEnumerable<SelectListItem>)*@ @Html.TextBoxFor(s=>s.CId) @Html.ValidationMessageFor(s => s.CId) </td> </tr> <tr> <td>@Html.LabelFor(s=>s.Gender):</td> <td> <!--生成 单选按钮的 方法,会根据 属性值 与 默认值 比较,如果相等,则设置为 选中!--> <!-- 也就是说,只要 当前Model中的Gender属性值,与 某个 单选按钮方法 设置的 value值一样,则自动设置为选中! --> @Html.RadioButtonFor(s => s.Gender, "男") 男 @Html.RadioButtonFor(s=>s.Gender,"女") 女 </td> </tr> <tr> <td colspan="2"> <input type="submit" id="btnSure" value="确 定"/> <input type="button" id="btnCancel" value="取 消"/> </td> </tr> </table> @Html.ValidationSummary() } <img src="/Helper/VCode" /> <img src="~/ValidateCode.ashx" />
代码
<script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script> <script type="text/javascript" src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
程序集