欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
無(wú)廢話(huà)MVC入門(mén)教程十[實(shí)戰二:用戶(hù)管理]
mvc問(wèn)題有問(wèn)必答,歡迎加群:

一、本文目標

學(xué)會(huì )制做MVC的管理相關(guān)功能

二、本文目錄

1.查詢(xún)

2.修改

3.刪除

4.代碼下載

1.查詢(xún)

1) View代碼:

 1 @model PagedList<MVC3.DemoModel.User> 2 @using Webdiyer.WebControls.Mvc; 3 @using (Html.BeginForm("Main", "Manage", FormMethod.Get)) 4 { 5     <span>用戶(hù)名:</span> 6     @Html.TextBox("username", ViewData["username"]) 7     <input type="submit" value="查詢(xún)" /> 8 } 9 @foreach (MVC3.DemoModel.User user in Model)10 {11     @user.UserID<span>---</span>@user.UserName<span>---</span> 12     @Html.ActionLink("修改", "UserEdit", new { id = user.UserID }) <span>---</span> 13     @Html.ActionLink("詳細", "UserDetail", new { id = user.UserID }) <span>---</span> 14     @Html.ActionLink("刪除", "UserRemove", new { id = user.UserID })<span>---</span> 15 16     <br />17 }18 <br />19 <br />20 @Html.Pager(Model, new PagerOptions21 {22     PageIndexParameterName = "id",23     ShowPageIndexBox = true,24     FirstPageText = "首頁(yè)",25     PrevPageText = "上一頁(yè)",26     NextPageText = "下一頁(yè)",27     LastPageText = "末頁(yè)",28     PageIndexBoxType = PageIndexBoxType.TextBox,29     PageIndexBoxWrapperFormatString = "請輸入頁(yè)數{0}",30     GoButtonText = "轉到"31 })32 <br />33 >>分頁(yè) 共有 @Model.TotalItemCount 篇留言 @Model.CurrentPageIndex/@Model.TotalPageCount

2)Control代碼:

 1         public ActionResult Main(int? id = 1) 2         { 3             ViewData["username"] = string.Empty; 4             if (Request.QueryString["username"] != null) 5             { 6                 ViewData["username"] = Request.QueryString["username"].ToString(); 7             } 8             List<Model.User> userList = new List<Model.User>(); 9             int totalCount = 0;10             int pageIndex = id ?? 1;11             userList = DemoRepository.User.GetList(ViewData["username"].ToString(), 2, (pageIndex - 1) * 2, out totalCount);12             PagedList<Model.User> mPage = userList.AsQueryable().ToPagedList(0, 2);13             mPage.TotalItemCount = totalCount;14             mPage.CurrentPageIndex = (int)(id ?? 1);15             return View(mPage);16         }

3)代碼解釋?zhuān)河捎趍vcPager渲染到客戶(hù)端后為<a href="Manage/Main/1">下一頁(yè)</a>,所以在查詢(xún)時(shí)只能以get的方式向服務(wù)器提交查詢(xún)條件,在View的代碼中我們要修改Form的提交方式

1 @using (Html.BeginForm("Main", "Manage", FormMethod.Get))

并且接收到參數后還要回顯到文本框中,在Control與View間我們使用ViewData["username"]做數據傳遞。

4)效果如下:

2.修改

1) View代碼:

 1 @model MVC3.DemoModel.User 2 @using (Html.BeginForm()) 3 { 4     @Html.LabelFor(user => user.UserName) 5     <br /> 6     @Html.TextBoxFor(user => user.UserName) 7     <br /> 8     @Html.LabelFor(user => user.Phone) 9     <br />10     @Html.TextBoxFor(user => user.Phone)11     <br />12     @Html.LabelFor(user => user.Residential)13     @Html.DropDownListFor(user => user.Residential, (SelectList)ViewBag.ViewResidential)14     @Html.LabelFor(user => user.UnitNo)15     @Html.DropDownListFor(user => user.UnitNo, (SelectList)ViewBag.ViewUnitNo)16     @Html.LabelFor(user => user.FloorNo)17     @Html.DropDownListFor(user => user.FloorNo, (SelectList)ViewBag.ViewFloorNo)18     @Html.LabelFor(user => user.DoorplateNo)19     @Html.DropDownListFor(user => user.DoorplateNo, (SelectList)ViewBag.ViewDoorplateNo)20     <br />21     @Html.HiddenFor(user => user.UserID)22     <input type="submit" value="修改" />23 }

2)Control代碼:

 1         public ActionResult UserEdit(int id) 2         { 3             //取出用戶(hù)信息 4             if (id != 0) 5             { 6                 Model.User user = DemoRepository.User.Get(new Model.User() { UserID = id }); 7  8                 //取出數據,并通過(guò)Helper把數據分解 9                 AddressHelper addressHelper = AddressHelper.GetInstance();10                 addressHelper.GetResidetialItem(GetList());11                 //反選并使用ViewBag傳到View12                 ViewBag.ViewResidential = new SelectList(addressHelper.ResidetialItem, "Value", "Text", user.Residential);13                 ViewBag.ViewFloorNo = new SelectList(addressHelper.FloorNoItem, "Value", "Text", user.FloorNo);14                 ViewBag.ViewUnitNo = new SelectList(addressHelper.UnitNoItem, "Value", "Text", user.UnitNo);15                 ViewBag.ViewDoorplateNo = new SelectList(addressHelper.DoorplateNoItem, "Value", "Text", user.DoorplateNo);16                 return View(user);17             }18             return View();19         }

3) 代碼解釋?zhuān)?/p>

1 ViewBag.ViewResidential = new SelectList(addressHelper.ResidetialItem, "Value", "Text", user.Residential);

是為了把數據庫中的數據反選到View上

4)運行效果:

3.刪除

1)View代碼:

1  @Html.ActionLink("刪除", "UserRemove", new { id = user.UserID }, new { @onclick = "return confirm('確定刪除嗎?');" })<span>---</span> 

2)Control代碼

1         //刪除用戶(hù)2         public void UserRemove(int id, FormCollection formCollection)3         {4             Model.User user = new Model.User() { UserID = id };5             DemoRepository.User.Remove(user);6             MessageBox.ShowAndRedirect(this, "刪除成功!", "/Manage/Main/");7         }

3)代碼解釋?zhuān)?/p>

View中加了“確認刪除嗎?”對話(huà)框。

Ciontrol中:int id, FormCollection formCollection:以HttpPost的方式進(jìn)行刪除。

4)運行效果:

4.代碼下載

[點(diǎn)擊下載]

版權:http://www.cnblogs.com/iamlilinfeng

活到老,學(xué)到老,練到老...
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
【.NET框架】—— MVC5+EF進(jìn)行CRUD(一)
[ASP.net教程]定制Asp.NET 5 MVC內建身份驗證機制
JS 表單 非空驗證
javascript分頁(yè)
blisshu‘s BLOG
【.NET框架】—— ASP.NET MVC5 表單和HTML輔助(二)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久