Ajax login with server-side validation using ASP.NET -


i'm writing asp.net application requires users log on server using external api. users given instant feedback, using ajax, if input invalid login credentials.

my view

@using (ajax.beginform("login", "login", null, new { id = "login-form" }))         {              <label>                 user name: @html.textbox("username", "", new { @class = "input" })             </label>             <label>                 password: @html.password("password", "", new { @class = "input" })             </label>             <input type="submit" class="button" value="login" />             <div id="login-validate">invalid login!</div>         } 

my controller

    public actionresult login(string username, string password)     {         // returns true if connection valid         if (repoconnection.verifyandbindconn(username, password))         {             return index(); // redirect home page, logged in new user         }         else         {             return null; // todo: don't change view         }     } 

is there way have controller not switch view, , instead call jquery function display error message?

just return view() in else block. redisplay login page.

    if (repoconnection.verifyandbindconn(username, password))     {         return index(); // redirect home page, logged in new user     }     else     {         return view(); // todo: don't change view     } 

if want ajaxy, going have change code not use form/submit button send login credentials via ajax, write session cookie, , handle redirect in js code.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -