title: Calling javascript function upon returning whatever kind of result in controller action
body: <p>I'm stuck with the following scenario:</p>
  
  <p>On my view there's a list of items. Depending on what the item represents, clicking on an item will take you to the appropriate view and display those results. Now displaying results in a view is not a problem; that is working fine. However, some items should be displayed in a popup and not in a view. I'm using a partial view together with bPopup and a javascript function like ShowListDialog(data) to show the dialog and bind the data. How do I call the javascript function upon returning whatever result needs be (I'm suspecting JavaScriptResult) in the action.</p>
  
  <p>What I think my action should look like at the moment is:</p>
  
  <p>public ActionResult ResponseItem(int reference)
  {
      ResponseBase response = repository.RetrieveResponse(reference);</p>
  
  <pre><code>if (response.ShouldShowInView)
  {
      return View(response.RedirectUrl, response.Data);
  }
  else
  {
      return JavaScript("ShowListDialog(" + response.Data.JsonString + ");");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have been looking at examples of return a JavaScript result and I can't even get that to work. If I say something like:</p>
  
  <p>return JavaScript("alert('Hello');");</p>
  
  <p>then in IE it asks me if I would like to open the javascript file; and in Chrome and Firefox it simply displays alert('Hello'); on the page.</p>
  
  <p>Thanks in advance for help :)
  D</p>