У меня есть запрос JSON, который проверяет сервер, было ли имя пользователя уже занято во время процедуры регистрации.
Это вызов jQuery:
// Instant check availability of the username
$("#txtUserName").blur(function() {
if ($("#txtUserName").val() == "") return;
$.ajax({
type: 'post',
url: '/Login/CheckUserName',
data: "{userName: '" + $("#txtUserName").val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(message) {
//Set the spanChecking text letting user know if the uname is available
if (message.d == true) {
$("#userNameCheck").css({ "color": "red", "font-weight": "bold", "font-size": "small", "padding-left": "5px" });
$("#userNameCheck").text("Non disponibile");
}
else {
$("#userNameCheck").css({ "color": "green", "font-weight": "bold", "font-size": "small", "padding-left": "5px" });
$("#userNameCheck").text("Disponibile");
}
},
error: function(errormessage) {
//this is just to see if everything is working. Remove before deploy
$j("#userNameCheck").text(errormessage.responseText);
}
});
});
, и этодействие контроллера, которое будет обслуживать запрос
[HttpPost]
public JsonResult CheckUserName( string userName ) {
if ( Membership.GetUser( userName ) == null )
return Json(false);
else
return Json(true);
}
В любом случае, я не понимаю, почему я получаю ошибку 500 с сервера.Глядя на это с помощью Fiddler, я вижу, что запрос RAW равен
POST http://localhost:1037/Login/CheckUserName HTTP/1.1
Host: localhost:1037
Connection: keep-alive
Referer: http://localhost:1037/Login/Register
Content-Length: 22
Origin: http://localhost:1037
X-Requested-With: XMLHttpRequest
Content-Type: application/json; charset=UTF-8
Accept: application/json, text/javascript, */*
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3
Accept-Encoding: gzip,deflate,sdch
Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
{userName: 'sampleuser'}
, но действие контроллера получает нулевой параметр для userName.Я вижу это через Fiddler и даже ставлю точку останова на код.
Где я делаю неправильно?
EDIT
Ошибка вернуласьклиент
The value cannot be null. Parameter name: username
Обратите внимание, что параметр Name в ошибке не сохраняет исходный регистр.Это поведение поставщика членства или я должен опустить регистр параметра?