1. 程式人生 > >用Html.BeginForm輔助方法進行easyui 的表單驗證

用Html.BeginForm輔助方法進行easyui 的表單驗證

程式碼片段如下(即可以用html的輔助方法,也可以用ajax的輔助方法):

 

@{

    ViewBag.Title = "Home Page";

}

@section styles

{

    <link rel="stylesheet" type="text/css" href="~/Content/themes/default/easyui.css">

}

<div class="jumbotron">

    <h1>

ASP.NET</h1>

</div>

<div class="row">

       <div class="col-md-4">             

        @*@using (Ajax.BeginForm("Search", "Home", new AjaxOptions{HttpMethod = "GET"}, new {id = "ff", onsubmit="return validateInput()"}))*@

        @using (Html.BeginForm("Search", "Home",  FormMethod.Get, new {id = "ff", onsubmit="return validateInput()"}))

        {

              <div>

                           <label for="name">Name:</label>

                           <input class="easyui-validatebox" type="text" name="name" data-options="required:true">

                     </div>

                     <div>

                           <label for="email">Email:</label>

                           <input class="easyui-validatebox" type="text" name="email" data-options="required:true,validType:'email'">

                     </div>

                     <div>

                           <label for="subject">Subject:</label>

                           <input class="easyui-validatebox" type="text" name="subject" data-options="required:true">

                     </div>

                     <div>

                           <label for="message">Message:</label>

                           <textarea name="message" style="height:60px;"></textarea>

                     </div>

                     <div>

                           <input type="submit" value="Submit">

                     </div>

        }

    </div>

</div>

@section scripts

{

    <script src="~/Scripts/jquery.easyui-1.4.5.min.js"></script>

    <script type="text/javascript">

        function validateInput(result) {

            return $("#ff").form('validate');

        }

    </script>

}