日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET MVC4 传递Model到View

發布時間:2025/5/22 asp.net 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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>

轉載于:https://www.cnblogs.com/zhuxiaoxiao/p/5548919.html

總結

以上是生活随笔為你收集整理的ASP.NET MVC4 传递Model到View的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。