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