ASP.NET MVC 如何把目前使用者所登入的帳號的資料表裡面有一個Name欄位帶入文字輸入框呢?
下面是我已經抓到目前使用者登入的帳號,並呈現到View頁面給客戶端看到,現在卡在要如何把紀錄註冊帳號的資料表裡面的名字欄位抓出來放到View上面給客戶端看到呢?
@{
ViewBag.Title = "購物車列表";
Layout = "~/Views/Shared/_LayoutMember.cshtml";
var UserName = User.Identity.Name;
<label for="fReceiver">帳號</label>
@Html.EditorFor(model => @UserName, new { htmlAttributes = new { @class = "form-control" } })
}
解法↓
@{
ViewBag.Title = "購物車列表";
Layout = "~/Views/Shared/_LayoutMember.cshtml";
var UserName = User.Identity.Name;
var admin = Model.tMembers.Where(m => m.fUId == UserName).FirstOrDefault();
<label for="fReceiver">帳號</label>
@Html.EditorFor(model => @UserName, new { htmlAttributes = new { @class = "form-control" } })
<label for="fReceiverPhone">姓名</label>
@Html.EditorFor(model => admin.fName, new { htmlAttributes = new { @class = "form-control" } })
}
一般可以用
class
var memberId = Member.Get_MemberId();
return View(memberId);
或者ViewBag
ViewBag.UserID
或者Session
Session["UserID"]