私はASP.NETの初心者で、コントローラの一時データを使用してViewBag
にデータを取得しようとしています。私はuser.Username
とuser.Email
でそれを得ましたが、それぞれViewBag.Name
とViewBag.Email
には入っていません。私のコードは、ViewBagでどうやって得ることができるのですか?ASP.NET:ViewBagの一時データにアクセスする
QuestionsContoller.cs
public class temp {
public string username { get; set; }
public string email { get; set; }
}
public ActionResult Question() {
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Question(User user) {
temp temp_user = new temp();
temp_user.email = user.Email;
temp_user.username = user.Username;
return RedirectToAction("Answers" , temp_user);
}
public ActionResult Answers(temp temp_user) {
User user = new Models.User();
user.Username = temp_user.username;
user.Email = temp_user.email;
ViewBag.Name = user.Username;
ViewBag.Email = user.Email;
return View(user);
}
「どのようにViewBagで取得できますか?」あなたのビューにあなたのViewBagデータを取得したいですか? – CodeNotFound
はい、それから私は私のビューでそれを取得します。 –
ビューにデータを取得する必要がありますか? – CodeNotFound