There are several tutorials for the new MVC5 templates that show you how to easily add new fields to a user's profile information. Here are a couple I have viewed:
My second link is the only tutorial that even mentions displaying the information back, but the tutorial is difficult to follow and that portion has so little information.
I want to display the user's birthdate on the Manage Account page, and maybe allow it to be edited. I have tried the following in AccountControllers.cs:[HttpPost]Manage():
if (ModelState.IsValid)
{
var currentUserID = User.Identity.GetUserId();
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(User.Identity.GetUserId());
ViewData.Add("userName", currentUser.UserName);
ViewData.Add("BirthDate", currentUser.BirthDate);
}
Using this code, the ViewBag items I set are both blank when I display them on Manage.cshtml with
<p>Birthdate is @ViewBag.BirthDate</p>
<p>ReturnURL is @ViewBag.ReturnUrl</p>
<p>UserName is @ViewBag.userName</p>
How do I show the information stored in the database?
I fixed this issue easily when I realized that the application will never hit the [HttpPost] version of the manage method until it's been submitted. I moved it into the default manage method and the code works just fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.