当@size指定时,MVC DropdownListFor html帮助程序会干扰JQuery提交

时间:2012-10-30 14:43:42

标签: jquery asp.net-mvc html-helper html.dropdownlistfor

我对MVC的html助手有这个奇怪的问题,因为当我为@ Html.DropdownListFor指定@size时,它会阻止jquery .submit与服务器通信。关于可能导致这种情况的任何想法?有没有其他方法可以让下拉高?这是代码:

           @using (Ajax.BeginForm("CreateInProgress", "Audit", new AjaxOptions {     
HttpMethod = "POST", OnSuccess = "CreateInProgressSuccess" }, new { id = "CreateInProgressMainForm"}))
           {
              <div id="reqTabContentBox" class="formPageContainer">
                  @Html.HiddenFor(x => x.ConfigDoc.CreateApproveButton.ConfigurableLabelDesc)
                  @Html.HiddenFor(x => x.ConfigDoc.CreateDisapproveButton.ConfigurableLabelDesc)
                  @Html.HiddenFor(x => x.ConfigDoc.CreateSaveButton.ConfigurableLabelDesc)
                  @Html.HiddenFor(x => x.ConfigDoc.CreateAdvanceButton.ConfigurableLabelDesc)

                  @Html.Partial("_CreateAudit")
               </div>
                       @Html.DropDownListFor(x => x.AuditDoc.AuditTemplateId, new SelectList(Model.AuditDoc.AuditTemplates, "Id", "Name"), new { size = "6", @class = "left" })
              <div id="finalButtons" class="formPageContainer">
                 <input id="AdvanceDirection" name="AuditDoc.AdvanceDirection" type="hidden" value="Forward" />

                  <span class="field-validation-error" id="CreateFormValidation"></span>  
                  <span class="field-validation-success" id="CreateSaveSuccess"></span> 
                  @if(Model.AuditDoc.CurrentStates.StateName == "Active")
                  {
                    <div class="btnContainer">
                       <input type="button" id="SaveCreateInProgress" class="toggleAllSelectors" value="@Model.ConfigDoc.CreateSaveButton.ConfigurableLabelDesc" />
                       <input type="button" id="AdvanceCreateInProgress" class="toggleAllSelectors" value="@Model.ConfigDoc.CreateAdvanceButton.ConfigurableLabelDesc" /> 
                    </div>
                  }
                  else
                  {
                    <label>@Model.ConfigDoc.AllEnterPrivateCommentLabel.ConfigurableLabelDesc</label> @Html.TextAreaFor(x => x.AuditDoc.PrivateComment, 0, 0, false)

                    <div class="btnContainer">
                       <input type="button" id="DisapproveCreateInProgress" class="toggleAllSelectors" value="@Model.ConfigDoc.CreateDisapproveButton.ConfigurableLabelDesc" @Model.OwnerApprovalAttribute />
                       <input type="button" id="ApproveCreateInProgress" class="toggleAllSelectors" value="@Model.ConfigDoc.CreateApproveButton.ConfigurableLabelDesc" @Model.OwnerApprovalAttribute />
                    </div>
                  }
               </div>
           }

这是jquery提交:

$("#CreateAuditMainForm").submit();

以下是Html dropdownlistfor helper生成的代码:

<select class="left valid" data-val="true" data-val-number="The field AuditTemplateId must be a number." data-val-required="The AuditTemplateId field is required." id="AuditDoc_AuditTemplateId" name="AuditDoc.AuditTemplateId" size="6" style="display: block; "> ... </select>

我会感激任何帮助或智慧的话语!

1 个答案:

答案 0 :(得分:0)

我不知道这是否是问题的原因,但是通过“select”字段提供的HTML,它不会被关闭。也许这会搞砸DOM结构,导致错误在jquery上提交表单。 尝试编辑html并关闭选择字段,然后重试提交以查看会发生什么。

<select class="left valid" data-val="true" data-val-number="The field AuditTemplateId must be a number." data-val-required="The AuditTemplateId field is required." id="AuditDoc_AuditTemplateId" name="AuditDoc.AuditTemplateId" size="6" style="display: block; " />

让我们看看我们是否能有一个幸运的猜测。 :P

问候。