0
使用ASP.NET 5 Web應用程序模板,並通過增加BUSINESSNAME管理擴展ApplicationUser
public class ApplicationUser : IdentityUser
{
public string BusinessName { get; set; }
中的DbContext的BUSINESSNAME屬性擴展ApplicationUser
public partial class CustomersContext : IdentityDbContext<ApplicationUser>
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>(entity =>
{
entity.HasIndex(e => e.BusinessName).HasName("BusinessNameIndex");
entity.Property(e => e.BusinessName)
.HasMaxLength(255)
.HasColumnType("varchar");
BUSINESSNAME也被添加到的ViewModels /管理/ IndexViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
namespace Customers.Web.ViewModels.Manage
{
public class IndexViewModel
{
public bool HasPassword { get; set; }
public IList<UserLoginInfo> Logins { get; set; }
public string BusinessName { get; set; }
public string PhoneNumber { get; set; }
public bool TwoFactor { get; set; }
public bool BrowserRemembered { get; set; }
}
}
ManageController指數動作稱爲
public async Task<IActionResult> Index(ManageMessageId? message = null)
{
ViewData["StatusMessage"] =
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
: message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
: message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
: message == ManageMessageId.Error ? "An error has occurred."
: message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
: message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
: "";
var user = await GetCurrentUserAsync();
var model = new IndexViewModel
{
HasPassword = await _userManager.HasPasswordAsync(user),
PhoneNumber = await _userManager.GetPhoneNumberAsync(user),
TwoFactor = await _userManager.GetTwoFactorEnabledAsync(user),
Logins = await _userManager.GetLoginsAsync(user),
BrowserRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user)
};
return View(model);
}
同時也查看/管理/ Index.cshml
@model IndexViewModel
@{
ViewData["Title"] = "Manage your account";
}
<h2>@ViewData["Title"].</h2>
<p class="text-success">@ViewData["StatusMessage"]</p>
<div>
<h4>Change your account settings</h4>
<hr />
<dl class="dl-horizontal">
<dt>External Logins:</dt>
<dd>
@Model.Logins.Count [<a asp-controller="Manage" asp-action="ManageLogins">Manage</a>]
</dd>
<dt>Business Name:</dt>
<dd>
@Model.BusinessName
</dd>
什麼是填充BUSINESSNAME正確的方法是什麼?
你能證明這渲染視圖中的控制器操作? –
添加了控制器操作。 – Vague