国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET MVC5網站開發之用戶資料的修改和刪除3(七)

2024-07-10 12:46:47
字體:
來源:轉載
供稿:網友

這次主要實現管理后臺界面用戶資料的修改和刪除,修改用戶資料和角色是經常用到的功能,但刪除用戶的情況比較少,為了功能的完整性還是坐上了。主要用到兩個action “Modify”和“Delete”。

一、用戶資料修改(Modify)

此功能分兩個部分:

public ActionResult Modify(int id) 用于顯示用戶信息

[httppost]

public ActionResult Modify(FormCollection form)用戶就收前臺傳來的信息并修改

1、顯示用戶信息

/// <summary>  /// 修改用戶信息  /// </summary>  /// <param name="id">用戶主鍵</param>  /// <returns>分部視圖</returns>  public ActionResult Modify(int id)  {   //角色列表   var _roles = new RoleManager().FindList();   List<SelectListItem> _listItems = new List<SelectListItem>(_roles.Count());   foreach (var _role in _roles)   {    _listItems.Add(new SelectListItem() { Text = _role.Name, Value = _role.RoleID.ToString() });   }   ViewBag.Roles = _listItems;   //角色列表結束   return PartialView(userManager.Find(id));  }

此action有一個參數id,接收傳入的用戶ID,在action中查詢角色信息,并利用viewBage傳遞到視圖,并通過return PartialView(userManager.Find(id))向視圖傳遞用戶模型返回分部視圖。

視圖代碼如下:

@model Ninesky.Core.User@using (Html.BeginForm()){ @Html.AntiForgeryToken() <div class="form-horizontal">  @Html.ValidationSummary(true, "", new { @class = "text-danger" })  @Html.HiddenFor(model => model.UserID)  <div class="form-group">   @Html.LabelFor(model => model.RoleID, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.DropDownListFor(model => model.RoleID, (IEnumerable<SelectListItem>)ViewBag.Roles, new { @class = "form-control" })    @Html.ValidationMessageFor(model => model.RoleID, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.Username, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.EditorFor(model => model.Username, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })    @Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.Sex, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.RadioButtonFor(model => model.Sex, 1) 男    @Html.RadioButtonFor(model => model.Sex, 0) 女    @Html.RadioButtonFor(model => model.Sex, 2) 保密    @Html.ValidationMessageFor(model => model.Sex, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })    @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })    @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.LastLoginTime, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.EditorFor(model => model.LastLoginTime, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })    @Html.ValidationMessageFor(model => model.LastLoginTime, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.LastLoginIP, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.EditorFor(model => model.LastLoginIP, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })    @Html.ValidationMessageFor(model => model.LastLoginIP, "", new { @class = "text-danger" })   </div>  </div>  <div class="form-group">   @Html.LabelFor(model => model.RegTime, htmlAttributes: new { @class = "control-label col-md-2" })   <div class="col-md-10">    @Html.EditorFor(model => model.RegTime, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })    @Html.ValidationMessageFor(model => model.RegTime, "", new { @class = "text-danger" })   </div>  </div> </div>}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉树县| 濮阳市| 钦州市| 岳普湖县| 西吉县| 花莲市| 莱芜市| 南汇区| 华蓥市| 隆回县| 汶川县| 河间市| 洪江市| 基隆市| 九寨沟县| 嘉鱼县| 江西省| 贵阳市| 肥西县| 乌兰县| 修水县| 三穗县| 宁都县| 宁乡县| 临汾市| 遂平县| 桃江县| 三门峡市| 雷山县| 翁源县| 凤台县| 屏边| 商都县| 政和县| 明水县| 康乐县| 安吉县| 蒙自县| 宝清县| 闸北区| 石首市|