Jquery validation in asp.net mvc
Posted
by
Suja
on Stack Overflow
See other posts from Stack Overflow
or by Suja
Published on 2011-01-15T06:45:32Z
Indexed on
2011/01/15
6:53 UTC
Read the original article
Hit count: 200
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.
© Stack Overflow or respective owner