I'm new to the MVC3 .NET. I want use jquery ajax function for login. I have read some solutions in this site. But when I use these methods and write my code it has one error. the ajax code is like below:
$(document).ready(function () {
$('#loginBut').click(function (e) {
var username = $('#username').val();
var password = $('#password').val();
$.ajax({
url: '/Admin/Login',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: {login: username, key:password},
success: function (msg) {
alert("username : " + msg.username);
}
});
$('#loginBut').blur();
});
});
and my admin controller with login method is like this :
public class AdminController : Controller
{
//
// GET: /Admin/
public ActionResult Index()
{
return View();
}
public ActionResult Login(string login, string key)
{
return Json(new { username = login, password = key});
}
}
the script is linked to the page. but after runnig and sending data I have this error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:1431/Admin/Login