title: ASP.NET MVC - How to display an "ActionResult" view that is returned to javascript?
body: <p>I'm using DotNetOpenAuth with a custom login provider to sign users into my site.  I have most of the code working, but am having an issue returning the view and displaying it so users can log into the provider.  Basically, the action is returning an actionresult which is the login page on the specific provider back to the calling javascript.  I expected this, as I need to get the login results back to the javascript.  Basically, what happens is I get some error about allowing access then three null boxes (look in the return of the call) and then nothing.  I need it to goto the provider site and log in.</p>
  
  <p>Data Example: url = <a href="https://www.google.com/accounts/o8/id" rel="nofollow">https://www.google.com/accounts/o8/id</a> , requiresUserName = false, username = test (assume it was entered into the textbox).</p>
  
  <p>Below is the code:</p>
  
  <p>JavaScript:</p>
  
  <pre><code>function ProviderSignOn(url, requiresUserName) {
      var username = $("#openUserNameText").val();
      if ((requiresUserName == 'True') &amp;&amp; (username == '')) {
          clickedProviderUrl = url;
          $('#openUserNameDiv').show('fast');
      }
      else {
          $('#openUserNameDiv').hide('fast');
          $("#openUserNameText").val('');
          $.ajax({
              type: "POST",
              url: "/Account/ProviderSignOn",
              data: "provider=" + url + "&amp;username=" + username,
              success: function (data) {
                  alert(data.Error);
                  alert(data.Message);
                  alert(data.Identifier);
              },
              failure: function (data) {
                  alert(data.Error);
                  alert(data.Message);
                  alert(data.Identifier);
              }
          });
      }
  }
  </code></pre>
  
  <p>Controller Action:</p>
  
  <pre><code>public ActionResult ProviderSignOn(string provider, string username)
      {
          string providerUrl = provider.Replace("{username}", username);
          bool error = true;
          string message = String.Empty;
          string identifier = String.Empty;
  
          var response = _openId.GetResponse();
  
          if (response == null)
          {
              Identifier id;
  
              if (Identifier.TryParse(providerUrl, out id))
              {
                  try
                  {
                      return _openId.CreateRequest(providerUrl).RedirectingResponse.AsActionResult();
                  }
                  catch (ProtocolException ex)
                  {
                      throw ex;
                  }
              }
              else
              {
                  error = true;
                  message = "Invalid";
                  identifier = String.Empty;
              }
          }
          else
          {
              switch (response.Status)
              {
                  case AuthenticationStatus.Authenticated:
                      error = false;
                      message = "Success";
                      identifier = response.ClaimedIdentifier;
                      break;
                  case AuthenticationStatus.Canceled:
                      error = true;
                      message = "Canceled";
                      identifier = String.Empty;
                      break;
                  case AuthenticationStatus.Failed:
                      error = true;
                      message = "Failed";
                      identifier = String.Empty;
                      break;
              }
          }
  
          return Json(new { Error = error, Message = message, Identifier = identifier });
      }
  </code></pre>