首页 > 代码库 > ASP.NET MVC传值
ASP.NET MVC传值
Controller
1 public ActionResult Index() 2 { 3 4 ViewData["num"] = 5; 5 6 ViewBag.count = 6; 7 8 TempData["num"] = 7; 9 10 uname un = new uname() { name = "Chris", pwd = "123" }; 11 12 ViewData["uname"] = un; 13 14 return View(un); 15 }
View
1 @{ 2 Layout = null; 3 } 4 @using Demo.Models; 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <meta name="viewport" content="width=device-width" /> 9 <title>Index</title> 10 </head> 11 <body> 12 <div> 13 <h1>视图 Index.cshtml</h1> 14 <hr /> 15 ViewData["num"]=@ViewData["num"]; 16 <hr /> 17 ViewBag.count=@ViewBag.count; 18 <hr /> 19 TempData["num"]=@TempData["num"]; 20 <hr /> 21 @{ 22 uname un = Model as uname; 23 } 24 @un.name-----@un.pwd; 25 <hr /> 26 <hr/> 27 @{uname ul = ViewData["uname"] as uname;} 28 @un.name-----@un.pwd; 29 </div> 30 </body> 31 </html>
结果:
ASP.NET MVC传值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。