1

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

Adam Pope
  • 3,234
  • 23
  • 32
user592899
  • 11
  • 1

0 Answers0