Reputation: 8525
I'm trying to create simple Ajax call, but after clicking the link I get a blank page with "Test" string in top left corner:
In my Details view I have:
@Ajax.ActionLink("test", "AddPositive", new AjaxOptions() { UpdateTargetId = "countDiv" })
<div id="countDiv">
</div>
In controller:
public string AddPositive()
{
String test = "Test";
return (test);
}
Action does get called.
In _Layout.cshtml I imported.
<script src="@Url.Content("/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
It's probably something really simple, but still cannot figure it out after going trough a few beginners tutorials for Ajax. Appreciate any help, thanks!
Upvotes: 2
Views: 5266
Reputation: 32137
<script src="/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
You are missing jquery and jquery.unobtrusive-ajax file.
Either there i bug in MicrosoftMvcAjax.js
or M.S. has forgot to mention these files on their Tutorial. I hardly use this feature (@Ajax.ActionLink
) so its tough for me figure out why it didnt worked without jQuery files.
Upvotes: 3
Reputation: 4803
You want to import two different .js files like so:
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
Also, I could be wrong, but doesn't your Action need to return an ActionResult?
Upvotes: 2