Referencing Scripts.Render("~/bundles/jqueryval") twice will force the Ajax.BeginForm to send two post requests when submitting my partial view

StackOverflow https://stackoverflow.com/questions/19765219

Question

I am working on a asp.net MVC web application, and I have the following main view:-

@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")
}

Which will render the following partial view, when clicking on the “Add Network Info” ajax link:-

@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") 

But clicking on the Save button inside my partial view , will send two post requests to the CreateVMNetwork Actino method. I think the problem Is related to the fact that I am referencing the @Scripts.Render("~/bundles/jqueryval") twice one at the main view and the second at the partial view. I have referenced the scripts twice because; on the main view I need the ajax feature for the ajax link, and on the partial view I need to validate the partial view fields according to the model data annotations. So can anyone advice how I can overcome this issue?

Thanks

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top