0

How do I go about hooking up my validation with jquery only? I do not want to use Microsoft ajax. I saw on this blog exactly what I want, but it seems that the file MicrosoftMvcJqueryValidator.js is deprecated or canceled.

Is there an official way to do this now? Possibly using asp.net mvc 3.

2 Answers 2

1

Everything you need to achieve this is already included with the ASP.NET MVC 3.0 Beta 1 template.

Model:

public class MyViewModel
{
    [Required]
    public string Value { get; set; }
}

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View(new MyViewModel());
    }

    [HttpPost]
    public ActionResult Index(MyViewModel model)
    {
        return View(model);
    }
}

View:

<script type="text/javascript" src="<%: Url.Content("~/scripts/jquery-1.4.1.js") %>"></script>
<script type="text/javascript" src="<%: Url.Content("~/scripts/jquery.validate.js") %>"></script>
<script type="text/javascript" src="<%: Url.Content("~/scripts/jquery.validate.unobtrusive.js") %>"></script>

<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) { %>
    <%: Html.TextBoxFor(x => x.Value) %>
    <%: Html.ValidationMessageFor(x => x.Value) %>
    <input type="submit" value="OK" />
<% } %>

If you want to do the same thing with ASP.NET MVC 2.0 you will need to download the source code of ASP.NET MVC Futures and extract MicrosoftMvcJQueryValidation.js from the package to include in your site.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use this plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.