日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

ASP.NET MVC4 传递Model到View

發(fā)布時(shí)間:2025/5/22 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET MVC4 传递Model到View 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

原文發(fā)表在:http://www.star110.com/Note/ReadArticle/60641215331146140043.html

開(kāi)發(fā)環(huán)境:.NET MVC4 + EF6.0

模型:

1 2 3 4 5 6 7 8 9 10 11 //Note列表數(shù)據(jù) ????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 //我的筆記首頁(yè)model ????public?class?NoteViewModel?:?BaseLayoutViewModel ????{ ????????//筆記列表 ????????public?List<NoteData>?Notes?{?set;?get;?} ????????public?NoteViewModel() ????????{ ????????????Notes?=?new?List<NoteData>(); ????????} ????}

?

?

后臺(tái)代碼:

1 2 3 4 5 6 public?ActionResult?Index(String?type?=?"",int?page?=?1) ????????{ ????????????//得到我的筆記視圖模型數(shù)據(jù) ????????????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">標(biāo)題</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>

轉(zhuǎn)載于:https://www.cnblogs.com/zhuxiaoxiao/p/5548919.html

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。