I have a view Known as Machinefilter
@using (Html.BeginForm())
{
<div id="filterDiv">
<fieldset>
<legend>Filter</legend>
<table>
<tr>
<td>
@Html.Label("Machine Serial No :")
</td>
<td>
@Html.TextBoxFor(m => m.MachineSrNo, new { @id = "SearchSerialNo" })
</td>
<td>
@Html.Label("City :")
</td>
<td>
@Html.DropDownListFor(m => m.CityId, new SelectList(ViewBag.Cities, "CityId", "CityName"), "--Select City--", new { @id = "drpCity" })
</td>
<td>
@Html.Label("Bank Branch :")
</td>
<td>
@Html.DropDownListFor(m => m.BankBranchId, new SelectList(ViewBag.BankBranch, "BankBranchId", "Name"), "--Select Bank Branch--", new { @id = "drpBankBranch" })
</td>
</tr>
</table>
</fieldset>
</div>
<p>
<input type="submit" value="Search" />
<input type="reset" value="Clear" />
</p>
}
Here whenever I click on "Search" button its shows default validation. Where i have not put any validation for this view.
ASP.NET MVC implictly does couple of validations even you don't decorate the properties with validation attributes. The couple of validations are type checking and required. These two validations will happen if you use non-nullable built-in data types like integer, datetime etc.
I hope you have properties as type integers. An integer property should have some value if you don't submit the implicit validation fails and you get an error.
To avoid this you can use nullable types.
For ex.
public class Model
{
public int? CityId{get;set;}
}
For MVC5, just add data_val = false to the helper you do not want validation on.
@Html.TextBoxFor(m => m.MachineSrNo, new { @id = "SearchSerialNo", data_val = false })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With