title: register via popup and pass result in this popup
body: <p>I realized registration and log on via popup window (Jquery UI Dialog).
  This is my <code>UserNavigation</code> control</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;dynamic&gt;" %&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $("#loginDialog").click(function () {
              $.get("/Account/LogOn",
                  function (htmlResult) {
                      $("#logon").remove();
                      $("#container").append(htmlResult);
                      $("#logon").dialog({ modal: true });
                  }
                      );
              return false;
          });
  
          $("#registerDialog").click(function () {
              $.get("/Account/Register",
                  function (htmlResult) {
                      $("#registration").remove();
                      $("#container").append(htmlResult);
                      $("#registration").dialog({ modal: true });
                  }
                      );
              return false;
          });
      });
  &lt;/script&gt;
  
  &lt;div id="userNavigation"&gt;
      &lt;%
      if (Request.IsAuthenticated)
      {
      %&gt;
      &lt;a href="/users/mr.freeman/profile" class="username"&gt;&lt;span&gt;&lt;%=Page.User.Identity.Name %&gt;&lt;/span&gt;&lt;i class="icon iUser"&gt;&lt;/i&gt;&lt;/a&gt;
      &lt;ul class="headLine_link"&gt;
          &lt;li&gt;&lt;a href="#"&gt;Profile settings&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;
              &lt;%= Html.ActionLink("Log off", "LogOff", "Account", null, new { @class = "exit" })%&gt;&lt;/li&gt;
      &lt;/ul&gt;
      &lt;%
      }
      else
      {%&gt;    
      &lt;ul class="headLine_link"&gt;
                      &lt;li&gt;&lt;%=Html.ActionLink("Register", "Register", "Account", null, new {id = "registerDialog"})%&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;%=Html.ActionLink("Log On", "LogOn", "Account", null, new {id = "loginDialog", @class = "username" })%&gt;&lt;/li&gt;
                  &lt;/ul&gt;
      &lt;%}%&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>It's works fine. But, I want that when the registration is successfull then show message in the same window. How can I do this?</p>
  
  <p>This is my controller:</p>
  
  <pre><code>[HttpPost]
          public ActionResult Register(RegisterModel model)
          {
              if (ModelState.IsValid)
              {
                  // Attempt to register the user
                  MembershipCreateStatus createStatus;
                  Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
  
                  if (createStatus == MembershipCreateStatus.Success)
                  {
                      //FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                      return RedirectToAction("Index", "Home");
                  }
                  else
                  {
                      ModelState.AddModelError("", ErrorCodeToString(createStatus));
                  }
              }
  
              // If we got this far, something failed, redisplay form
              return View(model);
          }
  </code></pre>
  
  <p>And, second question:  if the user performs some operation on the site that requires authorization, then show the login screen (if user not authorized).  </p>
  
  <p>I tryed use <code>Authorize</code> attribute, but not works.   </p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong>: Registration View:   </p>
  
  <pre><code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;DT.KazBilet.Web.Portal.Models.RegisterModel&gt;" %&gt;
  &lt;div id="registration"&gt;
      &lt;h2&gt;Create new account&lt;/h2&gt;
  
  
      &lt;script src="&lt;%: Url.Content("~/Scripts/jquery.validate.min.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="&lt;%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;% using (Html.BeginForm()) { %&gt;
          &lt;%: Html.ValidationSummary(true, "Error. Try again.") %&gt;
          &lt;div&gt;
              &lt;fieldset&gt;
                  &lt;legend&gt;Account Information&lt;/legend&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;%: Html.LabelFor(m =&gt; m.UserName) %&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      &lt;%: Html.TextBoxFor(m =&gt; m.UserName) %&gt;
                      &lt;%: Html.ValidationMessageFor(m =&gt; m.UserName) %&gt;
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;%: Html.LabelFor(m =&gt; m.Email) %&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      &lt;%: Html.TextBoxFor(m =&gt; m.Email) %&gt;
                      &lt;%: Html.ValidationMessageFor(m =&gt; m.Email) %&gt;
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;%: Html.LabelFor(m =&gt; m.Password) %&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      &lt;%: Html.PasswordFor(m =&gt; m.Password) %&gt;
                      &lt;%: Html.ValidationMessageFor(m =&gt; m.Password) %&gt;
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;%: Html.LabelFor(m =&gt; m.ConfirmPassword) %&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      &lt;%: Html.PasswordFor(m =&gt; m.ConfirmPassword) %&gt;
                      &lt;%: Html.ValidationMessageFor(m =&gt; m.ConfirmPassword) %&gt;
                  &lt;/div&gt;
  
                  &lt;p&gt;
                      &lt;input type="submit" value="Register" /&gt;
                  &lt;/p&gt;
              &lt;/fieldset&gt;
          &lt;/div&gt;
      &lt;% } %&gt;
  &lt;/div&gt;
  </code></pre>