Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Ajax.ActionLink not replacing partial view

I want to replace a div with a view using @Ajax.actionLink when I click on that link, but it isn't working.

Here is my link:

<div>
 <li>   @Ajax.ActionLink("settings","Create","Test",


new AjaxOptions { UpdateTargetId = "components" , InsertionMode = InsertionMode.Replace}
)  </li>
</div>

And my target div:

<div id="components">
</div>

I have also included these js file in the layout like that:

    <script src="~/Scripts/Controls/jquery-2.0.3.min.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script src="~/Scripts/modernizr-2.5.3.js"></script> 

And my action result:

    public PartialViewResult Create()
    {
        return PartialView("Create");
    }
like image 282
Shariful_Islam Avatar asked Jul 23 '14 08:07

Shariful_Islam


2 Answers

For people who installed Microsoft.jQuery.Unobtrusive.Ajax(trough nu-get or not) and want to use it through a bundle, don't forget:

  • To add the library in your bundleconfig. For example:

            bundles.Add(new ScriptBundle("~/bundles/unobtrusive").Include(
                     "~/Scripts/jquery.unobtrusive*"));
    
  • To Render it (mine is rendered in _Layout.cshtml):

    @Scripts.Render("~/bundles/unobtrusive")

I know its an old post, but can't hurt to add additional information, I guess.

like image 132
EyeSirvived Avatar answered Oct 19 '22 00:10

EyeSirvived


Believe it or not, I had everything setup correctly, except for one thing:

To install Microsoft jQuery Unobtrusive Ajax, run the following command in the Package Manager Console:

PM> Install-Package Microsoft.jQuery.Unobtrusive.Ajax -Version 3.2.2 

Instructions are here: https://www.nuget.org/packages/Microsoft.jQuery.Unobtrusive.Ajax/

like image 37
Henrique de Sousa Avatar answered Oct 18 '22 23:10

Henrique de Sousa