星空网 > 软件开发 > ASP.net

ASP.NET MVC4 传递Model到View

原文发表在:http://www.star110.com/Note/ReadArticle?id=54&title=ASP.NET+MVC4+%E4%BC%A0%E9%80%92Model%E5%88%B0View

开发环境:.NET MVC4 + EF6.0

模型:

1
2
3
4
5
6
7
8
9
10
11
//Note列表数据
    public class NoteData
    {
        public int Id { setget; }
        public String Author { setget; }
        public String title { setget; }
        public String Time { setget; }
        public int Read { setget; }
        public String TypeName { setget; }
        public String Url { setget; }
    }

 

1
2
3
4
5
6
7
8
9
10
//我的笔记首页model
    public class NoteViewModel : BaseLayoutViewModel
    {
        //笔记列表
        public List<NoteData> Notes { setget; }
        public NoteViewModel()
        {
            Notes = new List<NoteData>();
        }
    }

 

 

后台代码:

1
2
3
4
5
6
public ActionResult Index(String type = "",int page = 1)
        {
            //得到我的笔记视图模型数据
            NoteViewModel viewmodel= articlefunc.GetViewModel(type,page);
            return View("Index", viewmodel);
        }

前端代码:

注意:要在视图文件第一行声明model类型

@model NoteViewModel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<table class="table table-striped" id="dataTable" style="width:100%;">
                    <thead>
                        <tr>
                            <th>分类</th>
                            <th style="text-align:center">标题</th>
                            <th>作者</th>
                            <th>阅读</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var note in Model.Notes)
                        {
                            <tr>
                                <td>@note.TypeName</td
                                <td><i class="fa fa-columns">
                                    <a href="@note.Url" target="_blank"> @note.title</a>
                                    </i>
                                </td>
                                <td><i class="fa fa-user"> @note.Author</i></td>
                                <td>@note.Read</td>
                            </tr>
                        }
                    </tbody>
                </table>




原标题:ASP.NET MVC4 传递Model到View

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境快递费用:https://www.goluckyvip.com/tag/93499.html
snow——:https://www.goluckyvip.com/tag/935.html
跨境寄快递多少钱:https://www.goluckyvip.com/tag/93500.html
跨境货代收费标准:https://www.goluckyvip.com/tag/93501.html
跨境快递多少钱:https://www.goluckyvip.com/tag/93502.html
跨境电商的快递费多少钱:https://www.goluckyvip.com/tag/93503.html
温州旧货市场有玻璃柜卖吗?:https://www.vstour.cn/a/411246.html
如何用摄影作品表现“芳草鲜美,落英缤纷”的:https://www.vstour.cn/a/411247.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流