1

我正在开发一个 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") 

但是在我的局部视图中单击 Save 按钮,将向 CreateVMNetwork Actino 方法发送两个 post 请求。我认为问题与我在主视图中两次引用 @Scripts.Render("~/bundles/jqueryval") 和在局部视图中的第二次这一事实有关。我已经两次引用了这些脚本,因为;在主视图上,我需要 ajax 链接的 ajax 功能,在局部视图上,我需要根据模型数据注释验证局部视图字段。那么有人可以建议我如何克服这个问题吗?

谢谢

4

0 回答 0