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& ...
随机推荐
- 转:HTML5标准与性能之四:asm.js
HTML5标准与性能之四:asm.js Cong Liu (Intel) 于 星期五, 24/05/2013 - 01:13 提交 之前的几篇文章分别介绍了WebWorkers.Typed Array ...
- android之AlertDialog 点击其它区域自己主动消失
遇到一个问题记录下来,在开发中使用了AlertDialog,想点击屏幕其它区域的时候让这个dialog消失,一開始不做不论什么设置,在小米手机能够正常显示,可是在三星中却有问题.后来发现少了一个属性: ...
- BeginInvoke与Invoke的区别
简单的讲就是 BeginInvoke不需要等待方法运行完毕,就会继续执行下面的代码 Invoke则必须等待Invoke中的代码运行完毕,才会继续执行下面的代码. 可以通过下面的项目测试上面所描述的观点 ...
- android中的提示信息显示方法(toast应用)
android中的提示信息显示方法(toast应用) (2011-10-17 11:02:06) 转载▼ 标签: android toast 杂谈 分类: Android android中toast的 ...
- vs2010 rdlc .net4.0 卸载 Appdomain 时出错。 (异常来自 HRESULT:0x80131015) 解决办法
网上一看Appdomain出错,绝大部分都是说控件加载错误.经测试在.net 4.0环境下 rdlc报表很容易发生卸载 Appdomain 时出错. (异常来自 HRESULT:0x80131015) ...
- C# 使用 SAP NCO3.0 调用SAP RFC函数接口
最近使用C#调用SAP RFC函数,SAP提供了NCO3.0组件. 下载组件安装,之后引用“sapnco.dll”和“sapnco_utils.dll”两个文件. 在程序中 using SAP.Mid ...
- 打开jnlp Faild to validate certificate, the application will not be executed.
今天连jenkins, 本来好好的,只是我在一台机器上一直不断的启动不同的jnlp,绑定不同命名的slave, 然后突然就报错了, 如下截图所示:
- memcpy 和直接赋值的性能差异
不废话,看代码: #include <time.h> #include <stdint.h> #include <iostream> #define ARR_LEN ...
- Ajax请求WebService跨域问题 [转载]
1.背景 用Jquery中Ajax方式在asp.net开发环境中WebService接口的调用 2.出现的问题 原因分析:浏览器同源策略的影响(即JavaScript或Cookie只能访问同域下的内容 ...
- common.css
/* global */ document,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,p,blockqu ...