Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, it's possible. Just submit the login-form using the method <a href="http://weblogs.asp.net/mikebosch/archive/2008/02/15/asp-net-mvc-submitting-ajax-form-with-jquery.aspx" rel="noreferrer">described here by mike bosch</a> and return a json datastructure with the returnUrl if any.</p> <p>I have created a lightweight LoginResultDTO class that i return as json:</p> <pre><code>public class LoginResultDTO { public bool Success {get;set;} public string Message {get;set;} public string ReturnUrl {get;set;} } </code></pre> <p>Here's a script block from my LogOn view:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { var form = $($("form")[0]); form.submit(function() { var data = form.serialize(); $.post(form.attr("action"), data, function(result, status) { if (result.Success &amp;&amp; result.ReturnUrl) { location.href = result.ReturnUrl; } else { alert(result.Message); } }, "json"); return false; }); }); &lt;/script&gt; </code></pre> <p>This will ajax wrap the logon form. Note that this is the simplest implementation of the javascript code possible but it's a place to start.</p> <p>Then I have modified my LogOn action in the AccountController and in the relevant places put something like this:</p> <pre><code>if(Request.IsAjaxRequest()) { return Json(new LoginResultDTO{Success=true,Message="Successfully logged in"}); }else { return View(); } </code></pre> <p>So this is an ultralight but rather complete version of how jquery authentication could be done in asp.net mvc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload