【问题标题】:How do I display custom profile information with VS2013 MVC5 templates?如何使用 VS2013 MVC5 模板显示自定义配置文件信息?
【发布时间】:2013-11-05 07:39:38
【问题描述】:

有几个新的 MVC5 模板教程向您展示了如何轻松地将新字段添加到用户的个人资料信息中。以下是我看过的一对:

http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on

http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx

我的第二个链接是唯一一个甚至提到显示信息的教程,但是该教程很难理解,而且该部分的信息很少。

我想在“管理帐户”页面上显示用户的生日,并且可能允许对其进行编辑。我在 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);
}

使用此代码,当我在 Manage.cshtml 上显示时,我设置的 ViewBag 项目都是空白的

<p>Birthdate is @ViewBag.BirthDate</p>
<p>ReturnURL is @ViewBag.ReturnUrl</p>
<p>UserName is @ViewBag.userName</p>

如何显示存储在数据库中的信息?

【问题讨论】:

    标签: c# asp.net visual-studio visual-studio-2013 asp.net-mvc-5


    【解决方案1】:

    当我意识到应用程序在提交之前永远不会访问管理方法的 [HttpPost] 版本时,我轻松地解决了这个问题。我把它移到了默认的管理方法中,代码工作得很好。

    【讨论】:

      猜你喜欢
      • 2015-05-11
      • 2020-03-22
      • 1970-01-01
      • 2016-04-30
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      • 2014-10-27
      相关资源
      最近更新 更多