views:

427

answers:

4

Hi
I'm working on an asp.net ajax mvc application
I used Ajax.ActionLink method to add a link for updating span context using ajax, here is some part of my code :
...
<span id="status">No Status</span>
<%=Ajax.ActionLink("Update Status", "GetStatus", new AjaxOptions { UpdateTargetId = "status" })%>
...
but when I run application & click on created link, i get this error :
Microsoft JScript runtime error: 'Sys.Mvc.AsyncHyperlink' is null or not an object
can anybody help me please ???
thanks

A: 

Have you checked that the script you added to the page is :

<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

... check the spelling of MicrosoftMvcAjax. it should not be MicrosoftAjaxMvc.

jerbersoft
+4  A: 

Make sure you do this:

<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

And not this:

<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript" />

I couldn't believe that the latter does not work!

bitblit
That's insane! I would have never guessed this. Thanks
Ralph Shillington
Thanks, following the nerddinner tutorial my OCD made me close the tags as you did. Madness, but this was the cause of the exception I had too.
Ray Hayes
A: 

I also go the same error. Can you please let me know how did u solve this error.

<% = Ajax.ActionLink("Sort by Name in the grid", "SortEmployeeGrid", new { arg = SortingHelpers.SortParameter(lastSort, "EmpName", 3) }, sortOptions)%>

And here are my sort options

AjaxOptions sortOptions = new AjaxOptions()
{
    HttpMethod = "GET",
    UpdateTargetId="divMVCEmployeeGrid"
};
Aditya
+1  A: 

You have to make sure you include the javascript functions for AJAX on your web page:

I made a typo when I included the MicrosoftMvcAjax.js on my code, and got the same error.

If your application isn't at the top directory of your page, you can use the below code to resolve where your Scripts directory for your app is at.

<%
    string scriptsDir = Page.ResolveUrl("~/Scripts/");    
 %>

<script src="<%=scriptsDir %>MicrosoftAjax.js" type="text/javascript"></script>
<script src="<%=scriptsDir %>MicrosoftMvcAjax.js" type="text/javascript"></script>

Thanks!

WWC