原文发表在:http://www.star110.com/Note/ReadArticle/60641215331146140043.html

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

模型:

1
2
3
4
5
6
7
8
9
10
11
//Note列表数据
    public class NoteData
    {
        public int Id { set; get; }
        public String Author { set; get; }
        public String title { set; get; }
        public String Time { set; get; }
        public int Read { set; get; }
        public String TypeName { set; get; }
        public String Url { set; get; }
    }
1
2
3
4
5
6
7
8
9
10
//我的笔记首页model
    public class NoteViewModel : BaseLayoutViewModel
    {
        //笔记列表
        public List<NoteData> Notes { set; get; }
        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的更多相关文章

  1. ASP.NET MVC传递Model到视图的多种方式总结

    ASP.NET MVC传递Model到视图的多种方式总结 有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData ViewModel T ...

  2. ASP.NET MVC传递Model到视图的多种方式之通用方式的使用

    ASP.NET MVC传递Model到视图的多种方式总结——通用方式的使用 有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData Vi ...

  3. [转]ASP.NET MVC4中@model使用多个类型实例的方法

    本文转自:http://blog.csdn.net/hulihui/article/details/48199897 有时需要在ASP.NET MVC4的视图的@model中使用多个类型的实例,.NE ...

  4. ASP.NET MVC之model传值view

    控制器中,我们有时会在知道用户名的情况下,再获取相关数据 例如: public ActionResult Index()        {            UserInfo Entity_Tem ...

  5. ASP.NET MVC传递Model到视图的多种方式总结(二)__关于ViewBag、ViewData和TempData的实现机制与区别

    在ASP.NET MVC中,视图数据可以通过ViewBag.ViewData.TempData来访问,其中ViewBag 是动态类型(Dynamic),ViewData 是一个字典型的(Diction ...

  6. ASP.NET MVC传递Model到视图的多种方式总结(一)__通用方式的使用

    有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData ViewModel Tuple 场景: 在视图页面,下拉框选择课程触发事件,分别 ...

  7. asp.net mvc4中model与Model的区别

    @model模型定义 使用@model关键字可以定义一个Action里所对应的一个模型(经常可以叫他实体类), 其实是对动态变量进行实例化,这样就可以直接在cshtml文件中调用“Model”变量. ...

  8. ASP.NET MVC4中@model使用多个类型实例的方法

    转http://blog.csdn.net/hulihui/article/details/48199897

  9. ASP.NET MVC3中Controller与View之间的数据传递总结

    一.  Controller向View传递数据 1.       使用ViewData传递数据 我们在Controller中定义如下: ViewData["Message_ViewData& ...

随机推荐

  1. (转)Python rsa 签名与验证 sign and verify

    转自:http://wawehi.blog.163.com/blog/static/143780306201371361120515/ 网上一搜一大把的 python rsa 相关的东西,python ...

  2. canvas应用-思维导图

    canvas应用例子-思维导图 效果图如下: 函数说明: // 求圆上一点坐标,返回坐标点 function circlePoint(x, y, r, a) { var tmpx = x + r * ...

  3. ffrpc的php客户端lib

    摘要: ffrpc 是c++异步通讯库,使用ffrpc可以非常容易的构建服务器程序.为了使用方便,ffrpc提供了python.php的客户端lib,这样使用php于c++构建的server也是顺手拈 ...

  4. Android adt v22.6.2 自动创建 appcompat_v7 解决方法,最低版本2.2也不会出现

    Android 开发工具升级到22.6.2在创建工程时只要选择的最低版本低于4.0,就会自动生成一个项目appcompat_v7,没创建一个新的项目都会自动创建,很是烦恼... 之前在网上也找过方法, ...

  5. 一次流量稍高导致web项目慢的问题&解决

    项目上线后,用户越来越多,有一天出现一个issue:用户访问特别慢. 首先介绍下架构: haproxy/Nginx / \ node1 node2 | | redis redis(slave) | | ...

  6. 使用git提交内容到网盘

    1.创建版本库(注意勾选纯版本库的选项) 2.客户端获取版本库代码 3.提交及获取 master是git默认的主要分支(主干),适合单人独自开发.多人开发时可以给每个人创建一个分支 参考资料: htt ...

  7. Android Weak Handler:可以避免内存泄漏的Handler库

    这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! android使用java作 ...

  8. jQuery Mobile Data 属性

    按钮 带有 data-role="button" 的超链接.button 元素.工具栏中的链接以及 input 字段都会自动渲染成按钮样式,不需要添加 data-role=&quo ...

  9. [论文笔记] Legacy Application Migration to the Cloud: Practicability and Methodology (SERVICES, 2012)

    Quang Hieu Vu, Rasool Asal: Legacy Application Migration to the Cloud: Practicability and Methodolog ...

  10. MTNET 自用ios网络库开源

    短短两天就在https://git.oschina.net/gangwang/MTNET这里收获15个星 github 5星, 值得收藏! MTNET 自用ios网络库开源, 自用很久了,在数歀上架的 ...