Load partial view into div

前端 未结 4 2028
感动是毒
感动是毒 2020-12-05 05:51

I\'m trying to load a partial view into a div from a calling view, however the partial view loads into a new page. There isn\'t much code to it and I\'ve tried various ways

相关标签:
4条回答
  • 2020-12-05 06:15

    Your partial needs to be within the ajax form

    0 讨论(0)
  • 2020-12-05 06:24

    Couple of remarks about your code:

    • Ajax.* helpers in ASP.NET MVC 3 RC2 no longer use MS AJAX which has been deprecated in favor of jQuery, so your script inclusions are wrong. You need to include jquery
    • You have an ajax form without a submit button and an ajax link inside this form. This makes no sense. Either use an ajax form or an ajax link.

    So your code might look something among the lines:

    <script src="@Url.Content("~/scripts/jquery-1.4.4.js")" type="text/javascript"></script>
    
    @Ajax.ActionLink("Save", "Test", "Home", new AjaxOptions { 
        InsertionMode = InsertionMode.Replace, 
        UpdateTargetId = "mydiv"
    })
    
    <div id="mydiv">
        @Html.Partial("Test")
    </div>
    
    0 讨论(0)
  • 2020-12-05 06:28

    I think you should use <input type="submit" /> instead of @Ajax.Actionlink(...)

    in MVC4 you can add bundle @Scripts.Render("~/bundles/jqueryval") just after @Scripts.Render("~/bundles/jquery") or add script reference in script section in page view as shown below:

    @section scripts
        {
        <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
    
        }
    

    Good Luck.

    0 讨论(0)
  • 2020-12-05 06:32

    Add this line to your page (master page or layout)

    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
    

    just after MicrosoftMvcAjax.js line.

    0 讨论(0)
提交回复
热议问题