Greetings, bit of an issue with some validation...
Model:
public class Class1
{
[Required(AllowEmptyStrings = false, ErrorMessage="Error")]
public String test { get; set; }
}
Controller:
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public ActionResult TestClick()
{
return View();
}
}
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>
}
The TestClick() fires and does the post on first load without being validated...if text is changed validation prevents the post...how to validate before the jquery post??
精彩评论