サインアップフォームを作成しています。というテキストボックスがありUserName
ます。ボタンをクリックしたときにユーザー名の可用性を確認したい。asp.net MVC4 を使用しています。ボタンをクリックすると、次の関数が呼び出されました。ユーザー名がすでにデータベースにある場合は正常に返されますが、ユーザー名がデータベースにない場合は返されません。クエリの実行中に停止します。これは私の機能コードです。ユーザー名が利用できない場合は false を返したいです。
public JsonResult CheckUserName()
{
string userName = Request["UserName"];
var cx = new PostAdPage.Models.mydbEntities3();
// Stops at this line if username is not available
var u = cx.signups.First(x => x.username.Equals(userName));
if (u.username.Equals(userName))
{
return this.Json(true, JsonRequestBehavior.AllowGet);
}
else
{
return this.Json(false, JsonRequestBehavior.AllowGet);
}