两次引用Scripts.Render(“〜/ bundles / jqueryval”)会强制Ajax.BeginForm在提交部分视图时发送两个帖子请求

时间:2013-11-04 09:56:02

标签: asp.net-mvc razor partial-views cakephp-ajaxhelper

我正在开发一个asp.net MVC Web应用程序,我有以下主要观点: -

@model TMS.ViewModels.VMJoin

//code goes here
<p>
@Ajax.ActionLink("Add Network Info", "CreateVMNetwork","VirtualMachine",
    new { vmid = Model.VirtualMachine.TMSVirtualMachineID },
    new AjaxOptions {
 InsertionMode = InsertionMode.Replace,
 UpdateTargetId = "AssignNetwork"  ,
 LoadingElementId = "progress"


}
)
</p>
<p><img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress" /></p>
<div id ="AssignNetwork"></div>
<div id ="CreateEditNetwork"></div>
<table class="table table-striped table-bordered bootstrap-datatable datatable">
 <thead>
<tr>
<th class="f"> IP Address </th>
<th class="f"> MAC Address </th>
</tr></thead>
    <tbody id="networktable">   
    @foreach(var info in Model.VirtualMachine.Technology.TechnologyIPs){
        <tr id="@info.ID">
    <td> @info.IPAddress</td> 

    <td>@info.MACAddress</td>
<
    </tr>
    }
</tbody> 
    </table>


@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

点击“添加网络信息”ajax链接时会显示以下部分视图: -

@model TMS.ViewModels.AssignIps

    @if (this.ViewContext.FormContext == null) 
{
    this.ViewContext.FormContext = new FormContext(); 
}

@using (Ajax.BeginForm("CreateVMNetwork", "VirtualMachine", new AjaxOptions

{
    InsertionMode = InsertionMode.InsertAfter,
    UpdateTargetId = "networktable",
    LoadingElementId = "loadingimag",
    HttpMethod= "POST",
    OnSuccess="submitform"





}))
{
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model=>model.TechnologyIP.TechnologyID)

 @Html.AntiForgeryToken()
<div>
<span class="f">IP Address</span> 

@Html.EditorFor(model => model.TechnologyIP.IPAddress)
@Html.ValidationMessageFor(model => model.TechnologyIP.IPAddress)                                              

   <input type="CheckBox" name="IsTMSIPUnique" value="true" @(Html.Raw(Model.IsTMSMACUnique ? "checked=\"checked\"" : "")) /> IP Unique.    | 
 <span class="f"> MAC Address</span>       
@Html.EditorFor(model => model.TechnologyIP.MACAddress)
@Html.ValidationMessageFor(model => model.TechnologyIP.MACAddress)                                              

 <input type="CheckBox" name="IsTMSMACUnique" value="true" @(Html.Raw(Model.IsTMSMACUnique ? "checked=\"checked\"" : "")) /> MAC Unique.

</div>


       <input type="submit" value="Save" class="btn btn-primary"/>
}

    @Scripts.Render("~/bundles/jqueryval") 

但是点击部分视图中的“保存”按钮,会向CreateVMNetwork Actino方法发送两个帖子请求。我认为问题与我在主视图中引用@ Scripts.Render(&#34;〜/ bundles / jqueryval&#34;)两次的事实有关,而第二次在部分视图中引用。我已经两次引用了脚本,因为;在主视图上我需要ajax链接的ajax功能,在部分视图中我需要根据模型数据注释验证部分视图字段。那么有人可以建议我如何克服这个问题吗?

由于

0 个答案:

没有答案