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一定得是小写;下面用的时候首字母大写

posted @ 2019-10-15 15:58  橙-极纪元JJYCheng  阅读(527)  评论(0编辑  收藏  举报