问候,有些验证的问题......
型号:
public class Class1
{
[Required(AllowEmptyStrings = false, ErrorMessage="Error")]
public String test { get; set; }
}
控制器:
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public ActionResult TestClick()
{
return View();
}
}
查看:
<script type="text/javascript">
function TestClick() {
$.post("/Home/TestClick");
}
</script>
<h2>Index</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true);
@Html.EditorFor(mod => mod.test)
@Html.ValidationMessageFor(mod => mod.test);
<a href="#" onclick="TestClick()">Test</a>
}
TestClick()在第一次加载时触发并执行帖子而不进行验证...如果文本被更改验证会阻止帖子...如何在jquery post之前验证?