开发者

MVC Text Box Validation

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??

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜