asp.net mvc 传参和视图赋值--model传参
控制器
public ActionResult Index2() { Users model=new Users(){ UserName="小明",UserAge="30"}; return View("UserView",model); }
模型类
public class Users { public string UserName { set; get; } public string UserAge { set; get; } }
视图
@model GeRenWaiBao.com.Web.Models.Users @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>UserView</title> </head> <body> <h1>UserView</h1> <h2>@Model.UserName</h2> <h3>@Model.UserAge</h3> <h2></h2> </body> </html>
注意:视图:顶部的model一定得是小写;下面用的时候首字母大写
qq:527592435