前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ASP.NET MVC4开发指南_vue mvc

ASP.NET MVC4开发指南_vue mvc

作者头像
全栈程序员站长
发布2022-11-10 14:40:28
2920
发布2022-11-10 14:40:28
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

What is the WebGrid?

The WebGrid is a helper that was included on the new Beta 1 version of ASP.NET MVC 3 (Changes can happens since it is a beta version) that enable us to show data easily.

With a simple command @grid.getHtml() we have as return a populated table, with paging, sorting and alternated lines. Want more? yes, it follows the webstandards.

The WebGrid constructor takes a number of parameters. Only one is mandatory. Here’s an explanation of all of them:

System.Collections.Generic.IEnumerable sourceThe collection of objects

System.Collections.Generic.IEnumerable columnNames = nullThe names of the columns appearing in the grid

string defaultSort = null

The name of the column to sort the grid by default

int rowsPerPage = 10The number of rows to display per page is paging is enabled

bool canPage = trueDetermines if the WebGrid can be paged

bool canSort = trueDetermines if the WebGrid can be sorted

string ajaxUpdateContainerId = nullThe id of the containing element for Ajax paging and sorting support

string ajaxUpdateCallback = nullThe callback function for Ajax paging and sorting support

string fieldNamePrefix = nullThe value which prefixes the default querystring fields

string pageFieldName = nullA value that replaces the default querystring page field

string selectionFieldName = nullA value that replaces the default querystring row field

string sortFieldName = nullA value that replaces the default querystring sort field

string sortDirectionFieldName = nullA value that replaces the default querystring sortdir field

The GetHtml method renders the grid. To render a simple grid with no formatting, use the following code. I’m using the model that’s being passed in to the view for these examples.

Controller:

public ActionResult WebGrid()

{

return View(VideoRepository.FindAll().OrderByDescending(v=>v.CreateTime));

}

View:

@model IEnumerable

@{

ViewBag.Title = “WebGrid”;

Layout = “~/Areas/Admin/Views/Shared/Layout.cshtml”;

}

WebGrid

@{

var grid = new WebGrid(Model, rowsPerPage: 2);

@grid.GetHtml(

tableStyle: “data-table”,

columns: grid.Columns(

grid.Column(“Title”),

grid.Column(header: “Image”, format: (item) => Html.Raw(string.Format(“

“, item.ImageName))),

grid.Column(“CreateTime”, format: (item) => string.Format(“{0:d}”, item.CreateTime))

)

)

}

CSS:

/* data-table */

.data-table

{

border: #DDDDDD 1px solid;

width: 100%;

background:#FFF;

}

.data-table thead th

{

padding: 5px 10px;

text-align: left;

border: 1px solid #DDDDDD;

border-bottom: 1px solid #C1C8D2;

background-color: #F2F4F6;

font-size: 13px;

}

.data-table td

{

line-height: 20px;

padding: 5px 10px;

border: 1px solid #DDDDDD;

}

.data-table tr:hover

{

background-color: #F3F3F3;

}

.data-table td a

{

text-decoration: underline;

}

.data-table tfoot td

{

font-weight: bold;

padding: 10px 0;

text-align: center;

}

.data-table tfoot a

{

border: 1px solid #9AAFE5;

color: #2E6AB1;

display: inline-block;

margin: 0 2px;

padding: 0 5px;

text-decoration: none;

}

Result:

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/188881.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年9月27日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档