2

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!

tereško
  • 58,060
  • 25
  • 98
  • 150
mishap
  • 8,176
  • 14
  • 61
  • 92
  • At the very least you've imported the same javascript file twice. Don't do that. – Ben Finkel Dec 15 '11 at 21:00
  • and what do you have on your page before you click on the link. Does your page reload? – bobek Dec 15 '11 at 21:01
  • @bobek, yes the page view is loaded fine. After clicking on the link, I get empty page and Test in top left corner. I have both JS files imported. – mishap Dec 15 '11 at 21:11
  • @Ben Finkel, sorry about the typo, I have both imported and its the same problem mentioned. – mishap Dec 15 '11 at 21:12
  • by getting a page do you mean your page reloads? Did you check with Firebug console if there are any errors?? – bobek Dec 15 '11 at 21:20

2 Answers2

3
<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.

Praveen Prasad
  • 31,561
  • 18
  • 73
  • 106
2

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?

Ben Finkel
  • 4,753
  • 7
  • 34
  • 49