各位大神救命,关于.netMVC3 数据校验问题?
我的.netMVC3项目不能进行数据校验了,不管是客户端还是服务器端,都不行,我该做的配置都配置了,该引入的js文件也都引入了,但就是不行,下面是model的代码:
public class DepartmentCreateModel
{
[Required (ErrorMessage="请填写科室名称")]
[StringLength(20, ErrorMessage = "不能超过20个字符")]
[Display (Name="科室名称:")]
public string DepartmentName { get; set; } //科室名
[Required(ErrorMessage = "请填写科室编号")]
[StringLength(20, ErrorMessage = "不能超过20个字符")]
[Display(Name = "科室编号:")]
public string DepartmentNo { get; set; } //科室编号
[Required(ErrorMessage = "请填写科室创建人编号")]
[StringLength(20, ErrorMessage = "不能超过20个字符")]
[Display(Name = "创建人编号:")]
public string CreatedByUserId { get; set; }
}
Controller代码:
[HttpPost]
public ActionResult Create(DepartmentCreateModel department)
{
if (ModelState.IsValid)
{
Entities.Department d = new Entities.Department();
d.DepartmentNo = department.DepartmentNo;
d.DepartmentName = department.DepartmentName;
d.CreatedByUserId = department.CreatedByUserId;
d.CreatedByIpAddress = Request.UserHostAddress;
d.ModifiedByIpAddress = Request.UserHostAddress;
d.ModifiedByUserId = department.CreatedByUserId;
DateTime dt = DateTime.Now;
d.CreatedOnDate = dt;
d.ModifiedOnDate = dt;
departmentService.Add(d);
}
return RedirectToAction("Index");
}
页面代码:
@model LongQuan.Web.Areas.Admin.Models.DepartmentCreateModel
@{
ViewBag.Title = "新建科室信息";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="vsplitter">
<div id="left_menu">
<ul id="menu1">
<li><a href="/Admin/Department/Create">添加</a></li>
<li><a href="/Admin/Department/Index">查询</a></li>
<li><a href="#">刷新</a></li>
<li><a href="#">退回</a></li>
<li><a href="#">退出</a></li>
</ul>
</div>
<div style="padding-left: 50px">
<h2>
新建科室信息</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Department</legend>
<table>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.DepartmentName)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.DepartmentName)
@Html.ValidationMessageFor(model => model.DepartmentName)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.DepartmentNo)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.DepartmentNo)
@Html.ValidationMessageFor(model => model.DepartmentNo)
</div>
</td>
</tr>
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => model.CreatedByUserId)
</div>
</td>
<td>
<div class="editor-field">
@Html.EditorFor(model => model.CreatedByUserId)
@Html.ValidationMessageFor(model => model.CreatedByUserId)
</div>
</td>
</tr>
</table>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
</div>
</div>
关于验证的两个js文件在_Layout.cshtml中引进来了。
在web.xml中也配置了:
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
好像其他就没什么配置了吧,各位大神看看 到底是怎么回事啊?
在线等待。