Created
November 8, 2011 16:16
-
-
Save squidge/1348218 to your computer and use it in GitHub Desktop.
How to use AjaxContinuation in FubuMVC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function() { | |
$("#btnSubmit").click(function(e) { | |
e.preventDefault(); | |
$.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: "log-on", | |
data: $("#logonForm").serialize(), | |
success: function (response) { | |
/* when server-side validation fails AjaxContinuation output reads: | |
{ "success":false, | |
"errors":[{ | |
"category":null, | |
"field":"UserName", | |
"message":"Required Field" | |
}, | |
{ | |
"category":null, | |
"field":"Password", | |
"message":"Required Field" | |
} | |
] | |
} | |
*/ | |
if(response.success == false){ | |
for (var i=0; i<response.errors.length; i++) | |
$("#"+response.errors[i].field).addClass("error"); | |
} | |
}, | |
error:function(x,e){ | |
alert("error : " + x.status + " - " + e); | |
} | |
}); | |
}); | |
}); | |
</script> | |
<form id="logonForm" action="log-on" method="post"> | |
<label>Username</label> | |
<input type="text" id="UserName" name="UserName" /> | |
<label>Password</label> | |
<input type="password" id="Password" name="Password" /> | |
<input id="btnSubmit" type="submit" value="go"/> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PostHandler | |
{ | |
public FubuMVC.Core.Ajax.AjaxContinuation Execute(LogOnInputModel input) | |
{ | |
return new FubuMVC.Core.Ajax.AjaxContinuation | |
{ | |
Success = true | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment