ASP.NET MVC Validations
Posted
by Pinu
on Stack Overflow
See other posts from Stack Overflow
or by Pinu
Published on 2010-05-13T13:20:00Z
Indexed on
2010/05/13
13:24 UTC
Read the original article
Hit count: 276
ASP.NET
|asp.net-mvc
I need to validate the Advanced search form , but it has data to be sent to 2 different table people and documents so i am unable to use data annotations. I need to validate the Name to be characters only, account number & amount to be a number.How can i validate these fields?
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<center>
<img src="../../Content/images/DocuVault_Logo.png" alt="DocuVault" />
<%= Html.ValidationSummary() %>
<% using (Html.BeginForm("QuickSearch", "Search"))
{ %>
<div id="div_QuickSearch">
<table>
<tr>
<td colspan="2">
<%= Html.TextBox("search", "", new { style = "width: 300px" })%>
<input type="submit" value="Search" />
</td>
</tr>
<tr>
<td colspan="2">
<%= Html.ValidationMessage("search") %>
</td>
</tr>
<tr>
<td><a href="#" id="link_advanced">Advanced Search</a></td>
</tr>
</table>
<br />
</div>
<% } %>
<ul>
</ul>
</div>
<% using (Html.BeginForm("AdvancedSearch", "Search"))
{ %>
<div id="div_AdvancedSearch" style="display: none; width: 420px; padding: 10px;">
People
<table style="border: solid 1px black; padding: 5px; width: 400px;">
<tr>
<td>Name:</td>
<td align="right">
<%= Html.TextBox("searchName") %>
<%= Html.ValidationMessage("searchName")%>
</td>
</tr>
<tr>
<td>Address:</td>
<td align="right">
<%= Html.TextBox("searchAddress") %>
<%= Html.ValidationMessage("searchAddress")%>
</td>
</tr>
<tr>
<td>Account Number:</td>
<td align="right">
<%= Html.TextBox("searchAccountNumber") %>
<%= Html.ValidationMessage("searchAccountNumber")%>
</td>
</tr>
</table>
<br />
Documents
<table style="border: solid 1px black; padding: 5px; width: 400px;">
<tr>
<td>Invoice:</td>
<td align="right">
<%= Html.TextBox("searchInvoice") %>
<%= Html.ValidationMessage("searchInvoice")%>
</td>
</tr>
<tr>
<td>Amount:</td>
<td align="right">
<%= Html.TextBox("searchAmount") %>
<%= Html.ValidationMessage("searchAmount")%>
</td>
</tr>
<tr>
<td>Job:</td>
<td align="right">
<%= Html.TextBox("searchJob") %>
<%= Html.ValidationMessage("searchJob")%>
</td>
</tr>
<tr>
<td>SDI:</td>
<td align="right">
<%= Html.TextBox("searchSDI") %>
<%= Html.ValidationMessage("searchSDI")%>
</td>
</tr>
<tr>
<td>Date:</td>
<td align="right">
<%= Html.TextBox("searchDateBegin", "", new { style = "width: 88px" })%>
to
<%= Html.TextBox("searchDateEnd", "", new { style = "width: 88px" })%>
<%= Html.ValidationMessage("searchDate")%>
</td>
</tr>
</table>
<br />
<div style="width: 100%;">
<span style="float: left; margin-left: 10px;"><a href="#" id="link_quick">QuickSearch</a></span>
<span style="float: right; margin-right: 10px;"><input type="submit" value="Advanced Search" /></span>
</div>
</div>
<% } %>
</center>
</asp:Content>
© Stack Overflow or respective owner