Reputation: 263
I just want to Validate my HTML
text box required field validator in MVC 5
,
My View,its very important to use the onclick
event,please guide,I have already wasted 3 hours on this I know its very simply, I tried this link but it didn't worked
@using (Html.BeginForm("Search", "Controller"))
{
<input id="txtsearch" type="text" name="searchbox" />
<input id="Button1" type="submit" value="Search"
onclick="location.href='@Url.Action("Search","Video")'" />
}
Upvotes: 0
Views: 1996
Reputation: 1277
You can use the required/title attributes (http://www.w3schools.com/tags/att_input_required.asp)
<form action="@Url.Action("Search","Video")" method="POST">
<input id="txtsearch" type="text" name="searchbox" required title="Your validation message here." />
<input id="Button1" type="submit" value="Search" />
</form>
Custom HTML5 Form Validation: http://www.girliemac.com/blog/2012/11/21/html5-form-validation/
Browsers compatibility http://caniuse.com/#search=required
Upvotes: 1