1

新しく作成されたデフォルトの単純なMVC4Webプロジェクトを学習しています。

インデックスページには、ユーザーが自分のアカウントでサイトにログオンするためのリンクがあります。その後、彼は新しい名前、新しいパスワードを入力するためのフォームにリダイレクトされます。

このフォームを使用して検証する準備ができてい[Required]ます。しかし、リダイレクトされたページが完全に読み込まれるとすぐに、これらのコントロール(ユーザー名とパスワード)も検証されました(Field needs be filled in)。

ユーザーが自分のアカウントでログインした後のPOSTのコードは次のとおりです

if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
    return RedirectToCreateUser(returnUrl);
}

// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);

これがRedirectToCreateUserメソッドです

private ActionResult RedirectToCreateUser(string url)
{
    if (Url.IsLocalUrl(url))
    {
        return Redirect(url);
    }
    else
    {
        return RedirectToAction("CreateNewUser", "Account");
    }
}

最後に、httpGET用のCreateNewUserメソッド

public ActionResult CreateNewUser(CreateNewUserModel model)
{         
    return View(model);
}

もう1つはまだアクセスされていないと思うhttpPOST用です。

[HttpPost]
public ActionResult CreateNewUser(CreateNewUserModel model, string url)
{
    if (ModelState.IsValid)
    {
        // Attempt to register the user
        try
        {
            WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);
            WebSecurity.Login(model.UserName, model.Password);
            return RedirectToAction("CreateUserSuccess", "Account");
        }
        catch (MembershipCreateUserException e)
        {
            ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
        }
    }
    else
    {
    }
    return View(model);
}
4

2 に答える 2

0

CreateNewUserアクションはで起動し、無効[HttpPost]な(空の)クレデンシャルで投稿しようとしています。

次を使用して、この効果に何かを追加する必要があります[HttpGet]

[HttpGet]
public ActionResult CreateNewUser(CreateNewUserModel model)
{         
    return View(model);
}
于 2013-02-04T15:26:25.397 に答える
0

あなたの問題はここにあります

最後に、httpGET用のCreateNewUserメソッド

public ActionResult CreateNewUser(CreateNewUserModel model)
{         
    return View(model);
}

getリクエストのパラメータとしてオブジェクトを渡すことはできません。おそらくその署名は

public ActionResult CreateNewUser()
{    
    var model = new CreateNewUserModel();     
    return View(model);
}

または同様のもの

于 2013-02-04T16:01:25.467 に答える