0

我正在使用 MVC 2,aspx 视图引擎。我的问题是:客户端验证在部分视图中不起作用。

我的部分观点:

   <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IDM365.Web.Models.ContactInfoViewModel>" %>
   <%@ Import Namespace="IDM365.Web" %> 
   <script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
   <script src="/Scripts/jquery.validate.min.js"
type="text/javascript"></script>
   <script src="/Scripts/jquery.validate.unobtrusive.js"
type="text/javascript"></script>
   <script src="/Scripts/jquery.unobtrusive-ajax.min.js"
type="text/javascript"></script>

 <script type="text/javascript" language="javascript">

function validateForm() {


    return $('form').validate().form();
}

function CheckValidationForFirstTabOnly(IsFormSubmit) {


$('#btnCancel').attr('disabled', 'disabled');

 }
 }

</script>


<% Html.EnableClientValidation(); %>
<% using (Ajax.BeginForm("SaveContactInfo", "ManageUser", new AjaxOptions
{
   InsertionMode = InsertionMode.Replace,
   UpdateTargetId = "PopupBody",
   HttpMethod = "Post",
   OnBegin = "validateForm"
   ,
   OnComplete = " alert('Ajax success');"
}))
  { %>
  <div class="ciMain">
    <div id="result">
     <%: Html.ValidationSummary(true) %>
</div>

<div class="ciBox">
    <span class="ciLabel">
        <%: Html.LabelFor(m=>m.FirstName) %></span><div class="ciInputs">
            <%: Html.TextBoxFor(m => m.FirstName, new { @class = "ciTextbox", @style = "width: 110px !important;", @placeholder = "First Name" })%>
            <%:Html.ValidationMessageFor(m=>m.FirstName) %>
            <span class="ciSpacing2">&nbsp;</span>
            <%: Html.TextBoxFor(m => m.MiddleName, new { @class = "ciTextbox", @style = "width: 110px !important;", @placeholder = "Middle Name" })%>
            <span class="ciSpacing2">&nbsp;</span>
            <%:Html.TextBoxFor(m => m.LastName, new { @class = "ciTextbox",   @placeholder = "Last Name", @style = "width: 110px !important;" })%></div>
    <%: Html.ValidationMessageFor(m => m.LastName)%>
</div>

<div class="ciBox">
    <span class="ciLabel"></span>
    <div class="ciInputsButtons">
        <input type="submit" id="btnSaveAndClose" name="SubmissionType" value="Save" class="ciButton"
            onclick="return CheckValidationForFirstTabOnly(false);" />
        <input type="submit" value="Save and continue to next step" name="SubmissionType"
            id="btnSaveAndContinue" class="ciButton" onclick="return CheckValidationForFirstTabOnly(false);" />
        <input type="button" value="Cancel" class="ciButton" id="btnCancel" />
    </div>
</div>
 </div><% } %>

这是我的控制器:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult SaveContactInfo(FormCollection userViewModel, ContactInfoViewModel model, string SubmissionType)
    {
                 if (ModelState.IsValid)
                {

                }
                else
                {

                }
            }
            return View("ContactInfo", model);  
         }

这是我的模型:

public class ContactInfoViewModel : CommonPropertiesViewModel
{
    [Required]
    public string FirstName { get; set; }

    public string MiddleName { get; set; }

    [Required]
    public string LastName { get; set; }

}

在那,客户端验证不起作用。它缺少什么?

谢谢。

4

0 回答 0