本文介绍了视图页面中的客户端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我需要在视图页面中执行客户端验证.我正在使用asp .net mvc3
我的要求是,在表单页面中我有8个字段.如果用户未输入任何值并单击搜索按钮,则应显示一条警告消息以及一些消息
并且如果他输入的值不是数据库中存在的值,则它应该再次显示警报消息
我正在尝试使用以下If条件,但我无法显示任何内容.在此情况下,任何人都可以帮助我


if((myForm.getItemValue("Firstname")))!= null ||(myForm.getItemValue("Lastname"))!= null ||
(myForm.getItemValue("City")))!= null || (myForm.getItemValue("State")))!= null ||
(myForm.getItemValue("Country")))!= null || (myForm.getItemValue("College"))!= null){
这是我在查看页面中遇到的情况
我在查看页面中使用了Ajax
任何人请帮助我
谢谢

Hi all,
I need to perform client side validation in the view page.I am using asp .net mvc3
My requirement is that, in the form page i have 8 fields.if the user doesnt enter any value and click the search button it should display an alert message with some message
And in case if he enters any value other than which is present in the database it again should display alert message
I am trying this using the following If condition but i wasnt able to display anything.Could any one please help me in this


if ((myForm.getItemValue("Firstname")) != null || (myForm.getItemValue("Lastname")) != null ||
(myForm.getItemValue("City")) != null || (myForm.getItemValue("State")) != null ||
(myForm.getItemValue("Country")) != null || (myForm.getItemValue("College")) != null) {
This is the condition i took in my view page
I am using ajax in my view page
Any one please help me
Thanks

推荐答案

<script type="text/javascript">

function validate()
{
      if (document.getElementById("<%=tbFirstName.ClientID%>").value=="")
      {
                 alert("Name Field can not be blank");
                 document.getElementById("<%=tbFirstName.ClientID%>").focus();
                 return false;
      }
}
</script>


尝试这个.这可能有效.


try this. this might work.


这篇关于视图页面中的客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 06:59