ASP.NET MVC4 传递Model到View
原文发表在: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的更多相关文章
- ASP.NET MVC传递Model到视图的多种方式总结
ASP.NET MVC传递Model到视图的多种方式总结 有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData ViewModel T ...
- ASP.NET MVC传递Model到视图的多种方式之通用方式的使用
ASP.NET MVC传递Model到视图的多种方式总结——通用方式的使用 有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData Vi ...
- [转]ASP.NET MVC4中@model使用多个类型实例的方法
本文转自:http://blog.csdn.net/hulihui/article/details/48199897 有时需要在ASP.NET MVC4的视图的@model中使用多个类型的实例,.NE ...
- ASP.NET MVC之model传值view
控制器中,我们有时会在知道用户名的情况下,再获取相关数据 例如: public ActionResult Index() { UserInfo Entity_Tem ...
- ASP.NET MVC传递Model到视图的多种方式总结(二)__关于ViewBag、ViewData和TempData的实现机制与区别
在ASP.NET MVC中,视图数据可以通过ViewBag.ViewData.TempData来访问,其中ViewBag 是动态类型(Dynamic),ViewData 是一个字典型的(Diction ...
- ASP.NET MVC传递Model到视图的多种方式总结(一)__通用方式的使用
有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData ViewModel Tuple 场景: 在视图页面,下拉框选择课程触发事件,分别 ...
- asp.net mvc4中model与Model的区别
@model模型定义 使用@model关键字可以定义一个Action里所对应的一个模型(经常可以叫他实体类), 其实是对动态变量进行实例化,这样就可以直接在cshtml文件中调用“Model”变量. ...
- ASP.NET MVC4中@model使用多个类型实例的方法
转http://blog.csdn.net/hulihui/article/details/48199897
- ASP.NET MVC3中Controller与View之间的数据传递总结
一. Controller向View传递数据 1. 使用ViewData传递数据 我们在Controller中定义如下: ViewData["Message_ViewData& ...
随机推荐
- RabbitMQ学习笔记5-简单的RPC调用
利用空的queue名字("")让rabbitMQ生成一个唯一的队列名称,同时指定队列是:临时的(auto-delete).私有的(exclusive). 在发送的RPC调用消息里设 ...
- ecshop退出登录会清空购物车的bug优化,最完美解决方法
ecshop退出登陆后,会清空购物车,大家都应该知道有这样的勉强算bug的问题. 网上类似的教程相当多,但都有问题,说句不好听的,算是引新手入歧途! 总结网上方法如下: 1.修改init.php,把s ...
- LeetCode: Path Sum II 解题报告
Path Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals ...
- 我爱免费之FreeFileSync文件夹同步软件
因为项目需求用到FreeFileSync文件夹同步软件,这个软件好在免费.易用.功能强,我真的是大爱这种软件.http://freefilesync.com/ 可以下载免费软件,有需要的朋友,大可以一 ...
- System.Diagnostics.Stopwatch
System.Diagnostics.Stopwatch 注意:此类在 .NET Framework 2.0 版中是新增的.MSDN Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量 ...
- ZooKeeper与Curator注册和监控
Curator提供了对zookeeper客户端的封装,并监控连接状态和会话session,特别是会话session过期后,curator能够重新连接zookeeper,并且创建一个新的session. ...
- unity自动保存项目
原文来自于:http://wiki.unity3d.com/index.php?title=AutoSave#C.23_-_AutoSave.cs (奋斗的菜鸟_1029633680) 很多 ...
- POJ 3320 Jessica's Reading Problem
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6001 Accept ...
- 数轴上从左到右有n个点a[0],a[1]…,a[n-1],给定一根长度为L的绳子,求绳子最多能覆盖其中的几个点。要求算法复杂度为o(n)。
#include <iostream> using namespace std; int maxCover(int* a, int n, int l) { ; ; ; while(end ...
- xcode6.0 模拟器打不开
只要设置下这个就行了 本来以为虚拟机的问题 都把虚拟机从新安装了 杯具啊