欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MVC学习之二_____查看详情信息 博客分类: MVC4  

程序员文章站 2024-02-05 08:09:10
...
查看页和编辑页的模板页类似
@model BasicDataPageModel           //当前页数据源声明
@using Manager.Models.BasicData;
@{
    //Layout = null;   这句是不要加载默认模板
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>编辑</title>
    <link rel="stylesheet" type="text/css" href="~/Content/BasicData/div_table.css" />
</head>
<body>
    <br /><br />
    <form action="/BasicData/EditForm" method="post">
        <div class="table">
            <div class="tab_tr">
                <div class="tab-td">名称</div>
                <div class="tab-td"><input name="name" type="text" value="@Model.name" /></div>
            </div>
            <div class="tab_tr">
                <div class="tab-td">关键字</div>
                <div class="tab-td"><input name="key" type="text" value="@Model.key" readonly="readonly" /></div>
            </div>
            <div class="tab_tr">
                <div class="tab-td">值</div>
                <div class="tab-td"><input name="value" type="text" value="@Model.values" /></div>
            </div>
            <div class="tab_tr">
                <div class="tab-td">日期</div>
                <div class="tab-td"><input name="create_date" type="text" value="@Model.create_date" /></div>
            </div>
        </div>
        <div style="text-align:center">
            <br />
            <input type="submit" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重置" />
        </div>
    </form>
        

</body>
</html>



controller层代码
[HttpGet]
        public ActionResult Edit(string key)
        {
            if (key.Length > 0)
            {
                using (var db = new MyDbContext())
                {
                    AppBasicData model = db.AppBasicDatas.Where(x => x.Key == key).SingleOrDefault();
                    BasicDataPageModel bModel = new BasicDataPageModel();
                    bModel.key = model.Key;
                    bModel.create_date = DateTime.Parse(model.CreateDate.ToString());
                    bModel.name = model.Name;
                    bModel.values = model.Value;
                    return View(bModel);
                }
            }
            
            return View();
        }

备注:BasicDataPageModel 是单独定义的类 相比原来的类少了很多不必要的字段