如何在asp.net mvc中填充身份applicationuser数据?

时间:2018-04-19 05:09:38

标签: c# asp.net-mvc entity-framework asp.net-identity

我正在尝试添加一个关于用户的模型(ApplicationUser),为此我创建了一个模型我的问题是数据没有显示在视图中(特定帖子的用户名)

模型

public class OrganizationViewModel
{
    public ApplicationUser AppUser { get; set; }
    public int OrganizationId { get; set; }
    public string Name { get; set; }
}

控制器

public ActionResult Create(OrganizationViewModel organizationviewmodel)
        {
            var getuserid = User.Identity.GetUserId();
            var userid = db.Users.Single(s => s.Id == getuserid);
            var organizationvmodel = new Organization
            {
                AppUser = userid,
                Name = organizationviewmodel.Name
            };
            db.Organizations.Add(organizationvmodel);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

但是在视图中意味着index.cshtml,当我尝试将其填充为列表时,它就像这样output image

查看

   @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AppUser.UserName)
                @ViewBag.UserName
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.OrganizationId }) |
                @Html.ActionLink("Details", "Details", new { id = item.OrganizationId }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.OrganizationId })
            </td>
        </tr>
    }

请给我一个很好的解决方案,因为我对asp.net mvc

非常新

0 个答案:

没有答案