在没有模型和实体框架的情况下验证MVC 5中的HTML文本框

时间:2015-04-09 12:46:13

标签: html asp.net-mvc asp.net-mvc-5

我只想在HTML中验证我的MVC 5文本框必填字段验证程序,  我的观点,使用onclick事件非常重要,请指导,我已经浪费了3个小时,我知道它非常简单,我试过this link但它没有用

 @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")'" />
       }

1 个答案:

答案 0 :(得分:1)

您可以使用required / title属性(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>

自定义HTML5表单验证: http://www.girliemac.com/blog/2012/11/21/html5-form-validation/

浏览器兼容性 http://caniuse.com/#search=required

相关问题