@model PagedList@using Webdiyer.WebControls.Mvc; @{ } IndexPage 编辑页面的模板页代码@foreach (var item in Model) {名称key值value值创建时间操作}@item.Name@item.Key@item.Value@item.CreateDate@Html.ActionLink("编辑", "Edit",new {key = @item.Key}) |@Html.ActionLink("删除", "Delete", new { id = @item.Key})@Html.Pager(Model).Options(o => o.SetPageIndexParameterName("id").SetHorizontalAlign("right").SetPagerItemTemplate("{0} "))@model BasicDataPageModel @using Manager.Models.BasicData; @{ //Layout = null; 这句是不要加载默认模板 }编辑
备注:@Html.ActionLink("编辑", "Edit",new {key = @item.Key}) |@Html.ActionLink("删除", "Delete", new { id = @item.Key})
这句是实现跳转传值的设置,new {key = @item.Key}可以将key传递给具体的编辑页面
URL地址为xxxxx/xx/Eidt?key=xxxxx
new { id = @item.Key})传递后url表现形式是:xxxxx/xxx/xxxxx 默认ID省略了
Controller代码:
public void EditForm() { string name = Request.Form["name"].ToString(); string key = Request.Form["key"].ToString(); string value = Request.Form["value"].ToString(); string create_date = Request.Form["create_date"].ToString(); using (var db = new MyDbContext()) { try { AppBasicData model = db.AppBasicDatas.Where(x => x.Key == key).SingleOrDefault(); model.CreateDate = DateTime.Now; model.Name = name; model.Value = value; db.SaveChanges(); Response.Write(""); //给提示后,重定位到列表页 } catch { Response.Write(""); //给提示后,重定位到列表页 } } }