一、通过ViewBag传值:传值可以是字段和list等其他类型
后台代码
ViewBag.Message = "Your application description page.";
ViewBag.Message2 = "Your application description page2.";
ViewBag.Message3 = "Your application description page3.";
html页面获取代码:
二、通过ViewData:传值可以是字段和list等其他类型
后台代码:
ViewData["mess1"] = "测试1";
ViewData["mess2"] = "测试2";
List
ViewData["list"] = zsk;
HTML页面获取代码:
类型 | 分类 | 明细 | 操作 |
---|---|---|---|
@Html.DisplayFor(p => item.FLMC) | @Html.DisplayFor(p => item.LXMC) | @Html.DisplayFor(p => item.MEMO) | @Html.ActionLink("编辑", "UpdateZSK", "ZSK", new { zskdm = item.ZSKDM.ToString() }, null) |
三、通过TempData:传值可以是字段和list等其他类型,用法通ViewData
后台代码:
TempData["Tmptest1"] = "Tmptest1";
TempData["Tmptest2"] = "Tmptest2";
HTML页面获取代码:
四、直接在View中进行返回
后台代码:
List
zsk.Add(new ZSKObj {ZSKDM=1, FLMC="分类1", LXMC="整改措施", MEMO="整改测试1" });
zsk.Add(new ZSKObj { ZSKDM = 2, FLMC = "分类2", LXMC = "原因分析", MEMO = "原因分析测试1" });
zsk.Add(new ZSKObj { ZSKDM = 3, FLMC = "分类1", LXMC = "整改措施", MEMO = "整改测试2" });
ViewData["list"] = zsk;
return View(zsk);
HTML页面获取代码:
@{
ViewBag.Title = "About";
}
@model IEnumerable
类型 | 分类 | 明细 | 操作 |
---|---|---|---|
@Html.DisplayFor(p => item.FLMC) | @Html.DisplayFor(p => item.LXMC) | @Html.DisplayFor(p => item.MEMO) | @Html.ActionLink("编辑", "UpdateZSK", "ZSK", new { zskdm = item.ZSKDM.ToString() }, null) |
传递单个对象:
public ActionResult Edit(string id)
{
List
UserInfoViewModel item = dataList.Find(p => p.UserID.ToString() == id);
return View("Detail", item);
}
html代码:
@model MVC5Demo1.Models.UserInfoViewModel
@Html.HiddenFor(p => p.UserID)
五、参照网址:https://blog.csdn.net/fanbin168/article/details/39758291