Jquery validation in asp.net mvc
I have a view to create a DocumentTemplate
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="HexsolveMVC.Helpers" %> Create
<script type="text/javascript">
$(document).ready(function() {
$("#reset").click(function(event) {
$("#Part").get(0).selectedIndex = 0;
$("#txtDocTitle").val("");
$("#txtarDocDesc").val("");
});
});
});
</script>
<div class="container">
<div class="outer">
<div class="main_content">
<div>
<%=Html.BreadCrumb(Model.BreadCrumbs)%>
</div>
<div class="form_container">
<h1>
Document Template</h1>
<ul>
<li>
<label>
<span class="mandatory">*</span>Engine model:</label>
<%=Html.DropDownList("Part", (SelectList)ViewData["Part"])%>
<span class="tagline">Please select the engine model
<%--<a href="#">Need Help</a>--%></span> </li>
<li>
<label>
<span class="mandatory">*</span>Document Title:</label>
<input id="txtDocTitle" name="docTitle" type="text" class="formstyle" />
</li>
开发者_开发问答 <li>
<label>
Discription:</label>
<textarea name="docDesc" id="txtarDocDesc" cols="45" rows="5"></textarea>
</li>
<li>
<div class="button_panel">
<input name="button" type="submit" class="btn_create_doc_big" id="button" value="Create" />
<span class="reset_field"><a href="#" id="reset">Reset the form</a></span><span class="mandatory_tag">[
<span class="mandatory">*</span> Mandatory fields ]</span>
<div class="clear">
</div>
</div>
<span class="tagline">By clicking on '<span class="tagline_highlight">Create</span>'
button your document will be created.<br />
And after you can add new instructions and subsections easily.</span></li>
</ul>
<div>
<h2>
Example of how to work a document
</h2>
<img alt="" src="../../html/images/diagram.jpg" width="738" height="172" /></div>
</div>
</div>
<div class="clear">
</div>
</div>
</div>
I need to validate the txtDocTitle since its a required field. How can i do this using jQuery. I cannot use Model validation coz this same model is used for other views also and it have properties from other tables. I need something to do with jQuery.
Check out jQuery validate
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
You can even set up MVC2 and MVC3 to use it for model validation
http://www.tikalk.com/net/aspnet-mvc-2-client-side-validation-using-jquery-validation-plug
精彩评论