views:

128

answers:

3

The bad 'return JavaScript' goes like this:

  1. This is the action link that gets selected.

    Ajax.ActionLink("Sign Out", "LogOff", "Account", new AjaxOptions { })
    
  2. This is the action.

    public ActionResult LogOff()   
    {      
        FormsAuth.SignOut();   
        return JavaScript("ClearDisplayName()");  
    }
    
  3. The JavaScript is never called !

Additioinal Info:

All javascript functions are all in the .js file.

Four other actions, in the same file, do their return JavaScript(...) successfully.

I tested the four working actions by doing a return JavaScript("ClearDisplayName()") and they all call ClearDisplayName() successfully.

I tested the failing action by doing a return JavaScript("OtherKnownWorkingJava()") with no luck.

Any idea's for this weird behavior ?

I noticed that all the successful actions pass through a View first. The troubled action does not, it comes directly from an ActionLink.

A: 

Is FormsAuth properly defined? Shouldn't that be FormsAuthentication?

gWiz
A: 

Are other actions also invoked by Ajax.ActionLink?

I doubt it Ajax.ActionLink will process the JavaScript return. If so, you either process the result yourself (using eval(response)), or avoid using Ajax.ActionLink, or return view instead that has $(document).ready(function(){<%=ViewData["jsfunc"]%>};); - this will most likely be processed, though you'll need jQuery.

queen3
+1  A: 

After throwing some mud against this problem here's how I was able to call 'return JavaScript("ClearDisplayName")'.

Instead of trying to do 'return JavaScript("ClearDisplayName") from the LogOff action, I redirected to another action, LogOffA, and did a 'return JavaScript("ClearDisplayName") there, and it worked !!

    public ActionResult LogOffA()
    {
        return JavaScript("ClearDisplayName()");
    }

    public ActionResult LogOff()
    {
        FormsAuth.SignOut();
        return RedirectToAction("LogOffA", "Account");
        //return JavaScript("ClearDisplayName()");
    }
A. Elliott