【问题标题】:Ajax beginform() is not workingAjax beginform() 不工作
【发布时间】:2014-05-31 09:52:09
【问题描述】:

我正在尝试使用 ajax 表单开始加载部分视图,特别是 div 但它不能同时工作,请在单击提交按钮时帮助我,我需要将我的部分视图加载到 div 中

母版页:

   <body>
<form id="form1" runat="server" enctype="multipart/form-data" >    
<div>
 <div>
    <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">PageName</asp:ContentPlaceHolder> 
    <div id="content">
       <div id="sidebar">

        <asp:Menu ID="menuBar" StaticEnableDefaultPopOutImage="False" runat="server"
                BackColor="Black" DynamicHorizontalOffset="2" Font-Names="Arial" Font-Size="0.8em"
                ForeColor="White" StaticSubMenuIndent="10px">
                <DynamicHoverStyle BackColor="White" ForeColor="Black" BorderColor="Black" BorderStyle="Solid"
                    BorderWidth="1px" />
                <DynamicMenuItemStyle HorizontalPadding="10px" VerticalPadding="7px" BorderColor="White"
                    BorderStyle="Solid" BorderWidth="1px" Font-Names="Arial" Font-Size="12px" />                                        
                                    <StaticSelectedStyle BackColor="White" BorderColor="Black" BorderStyle="Solid"
                    BorderWidth="1px" ForeColor="Black" />                    
            </asp:Menu>               
       </div>            
      <div id="main">
          <asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder> 
       </div>
      </div>         
</form>

查看页面:

 <%  using (Ajax.BeginForm("GetTruckExpensesChild", new { id="EX1001" }, new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "List" }))
       {%>
    <%: Html.ValidationSummary(true)%>
    <div> <input type="submit" name="dina" value="show list" </div>
    <div id="List">  </div>

【问题讨论】:

    标签: ajax asp.net-mvc c#-4.0 model-view-controller partial-views


    【解决方案1】:

    确保您应该添加以下捆绑包。

    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
    
    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.unobtrusive*"));
    

    在您的 HTML 中,确保调用了这两个包。

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

    详情请查看此链接 -

    Using AJAX to load a partial view not working

    【讨论】:

    猜你喜欢
    • 2011-04-29
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多