0

我的 asp.net mvc Web 应用程序中有以下代码:-

@using (Ajax.BeginForm("AdvanceSearchIndex","Home",
new AjaxOptions
{
    HttpMethod = "get",
    InsertionMode = InsertionMode.Replace,
    LoadingElementId = "progress",
    UpdateTargetId = "SearchTable"
}))
{





    <p><span class="f">IP Address <input  placeholder="Search by IP " name="ip" type="text"  /> </span></p>
   <p><span class="f">MAC Address <input  placeholder="Search by Mac " name="mac" type="text"  /> </span></p>




<input class="btn btn-success" type="submit" value="search" /> 

<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress" />

    }

但我需要编写一个 javaScript 代码,以便在单击“搜索”按钮时 IP 地址或 MAC 地址不为空或为空?

4

1 回答 1

1

我也在这里回答了你:如何实现必需的验证来检查用户是否输入了至少一个值

        @using (Ajax.BeginForm("AdvanceSearchIndex","Home",
        new AjaxOptions
        {
            HttpMethod = "get",
            InsertionMode = InsertionMode.Replace,
            LoadingElementId = "progress",
            UpdateTargetId = "SearchTable",
            OnBegin = "validateForm"//note this line calling js function
        }))
        {  

            <p><span class="f">IP Address <input  placeholder="Search by IP " name="ip" type="text"  /> </span></p>
           <p><span class="f">MAC Address <input  placeholder="Search by Mac " name="mac" type="text"  /> </span></p>

        <input class="btn btn-success" type="submit" value="search" /> 

        <img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress" />
    }

        <script>
        function validateForm(){
           //return true/false
           return $("[name=ip]").val() !="" || $("[name=nac]").val()
        }
        </script>  
于 2013-10-30T11:44:34.383 回答