Why does Partial View show as full page in MVC 5 Visual Studio 13?

后端 未结 4 1206
春和景丽
春和景丽 2021-01-02 05:59

I\'m trying to replace part of a page with a partial view in ASP.Net MVC 5 (Visual Studio 13) using the following:

Views/Book/Index.cshtml:

相关标签:
4条回答
  • 2021-01-02 06:28

    1.Install Microsoft.jQuery.Unobtrusive.Ajax using NuGet

    2.Add reference to Jquery and Unobtrusive in your _Layout.cshtml

    @Scripts.Render("~/bundles/jquery")
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js" >

    0 讨论(0)
  • 2021-01-02 06:31

    As an additional note on getting this working. I'm hoping VS 2013 RTM includes this but either way this should get you up and running

    • Install jquery-validate via nuget by going to tools-library package manager->package manager console and entering in
    install-package Microsoft.jQuery.Ajax.Unobtrusive
    
    • Configure your bundle in your /app_start/bundleconfig.cs
    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
        "~/Scripts/jquery.unobtrusive*",
        "~/Scripts/jquery.validate*")
    );
    
    • Add your bundle to your _layout.cshtml either beneath your
    @Scripts.Render("~/bundles/jquery")

    or include it in each view you want to use it in

    @section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
    }
    
    0 讨论(0)
  • 2021-01-02 06:46

    Turns out that jquery.unobtrusive-ajax.js is not included by default. Adding it solved the problem.

    0 讨论(0)
  • 2021-01-02 06:46

    I had the same problem drove me nuts with unobtrusive Ajax in MVC with a begin form select list filter getting updated and the list re-displayed as a partial view. I added the first two items below but realized I also needed the last two. Once added the partial view results appeared very nicely.

     <script src="~/Scripts/jquery-ui.unobtrusive-2.1.0.js" ></script>         
     <script src="~/Scripts/jquery-ui.unobtrusive-2.1.0.min.js" ></script>        
     <script src="~/Scripts/jquery.unobtrusive-ajax.js" ></script>         
     <script src="~/Scripts/jquery.unobtrusive-ajax.min.js" ></script>    
    
    0 讨论(0)
提交回复
热议问题