private List<CurrentUser> _UserList = new List<CurrentUser>()
{
new CurrentUser()
{
Id=1,
Name="人工智能1",
Account="Administrator",
Email="57265177@qq.com",
LoginTime=DateTime.Now,
Password="123456"
},
new CurrentUser()
{
Id=2,
Name="人工智能2",
Account="Administrator",
Email="57265177@qq.com",
LoginTime=DateTime.Now,
Password="123456"
},
new CurrentUser()
{
Id=3,
Name="人工智能3",
Account="Administrator",
Email="57265177@qq.com",
LoginTime=DateTime.Now,
Password="123456"
},
new CurrentUser()
{
Id=4,
Name="人工智能4",
Account="Administrator",
Email="57265177@qq.com",
LoginTime=DateTime.Now,
Password="123456"
}
};
public ActionResult Index(int i)
{
logger.Info($"调用Index Action 参数为:{i}");
base.ViewData["ViewDataCurrentUser"] = _UserList[0];
base.ViewData["testProp"] = "jeff";
base.ViewBag.testProp = "判断ViewBag.testProp 有没有覆盖ViewData[testProp]";
base.ViewBag.Name = "aaaaaaaaaaaaaaaaaaaaaaaaa";
base.ViewBag.ViewBagCurrentUser = this._UserList[1];
base.TempData["TempDataCurrentUser"] = this._UserList[2];
base.TempData["testProp"] = "fresh";
if (i == 1)
{
CurrentUser currentUser = this._UserList[3];
return View(currentUser);
}
else
{
return RedirectToAction("Index1");
}
}
@using Advanced.AspNetMVC.Models
@model CurrentUser
@{
ViewBag.Title = "FirstIndex";
CurrentUser ViewDataCurrentUser = ((CurrentUser)ViewData["ViewDataCurrentUser"]);
CurrentUser TempDataCurrentUser = ((CurrentUser)TempData["TempDataCurrentUser"]);
}
<h2>FirstIndex</h2>
<h3>ViewData["ViewDataCurrentUser"].Name:@(((CurrentUser)ViewData["ViewDataCurrentUser"]).Name)</h3>
<h3>ViewData["ViewDataCurrentUser"].Name:@(ViewDataCurrentUser.Name)</h3>
<h3>ViewData["testProp"]:@ViewData["testProp"]</h3>
<h3>ViewBag.Name:@ViewBag.Name</h3>
<h3>ViewBag.ViewBagCurrentUser.Name:@ViewBag.ViewBagCurrentUser.Name</h3>
<h3>TempData["TempDataCurrentUser"].Name:@(((CurrentUser)TempData["TempDataCurrentUser"]).Name)</h3>
<h3>TempData["TempDataCurrentUser"].Name:@(TempDataCurrentUser.Name)</h3>
<h3>TempData["testProp"]:@TempData["testProp"]</h3>
<h3> ViewBag.testProp:@ViewBag.testProp</h3>
<h3>Model.Name:@Model.Name</h3>
views 下面的web.config定义
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<!--cshtml的父类,也可以扩展-->
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
[AcceptVerbs(HttpVerbs.Put | HttpVerbs.Post)]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ProductId, CategoryId, Title, Price, Url, ImageUrl")]JDCommodity commodity)
{
string title1 = this.HttpContext.Request.Params["title"];
string title2 = this.HttpContext.Request.QueryString["title"];
string title3 = this.HttpContext.Request.Form["title"];
if (ModelState.IsValid)
{
JDCommodity newCommodity = this._iCommodityService.Insert(commodity);
return RedirectToAction("Index");
}
else
{
throw new Exception("ModelState未通过检测");
}
}