ASP.NET MVC4开发指南_vue mvc

ASP.NET MVC4开发指南_vue mvcWhatistheWebGrid?TheWebGridisahelperthatwasincludedonthenewBeta1versionofASP.NETMVC3(Changescanhappenssinceitisabetaversion)thatenableustoshowdataeasily.Withasimp…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

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(“%7B0%7D%5C%22“, 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:

2509349417392372736.png

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

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

(0)
上一篇 2026年4月15日 上午11:52
下一篇 2026年4月15日 上午11:58


相关推荐

  • java小程序实例大全_12个用Java编写基础小程序&经典案例(收藏)

    java小程序实例大全_12个用Java编写基础小程序&经典案例(收藏)原标题:12个用Java编写基础小程序&经典案例(收藏)如果是刚接触或者刚学习java,练习一些基础的算法还是必须的,可以提升思维和语法的使用。1、输出两个int数中的最大值importjava.util.Scanner;publicclassdemo{publicstaticvoidmain(String[]args){Scannerscanner=newSc…

    2022年7月7日
    37
  • MATLAB 之 wavedec2函数详解

    MATLAB 之 wavedec2函数详解wavedec2函数:1.功能:实现图像(即二维信号)的多层分解,多层,即多尺度.2.格式:[c,s]=wavedec2(X,N,’wname’)    [c,s]=wavedec2(X,N,Lo_D,Hi_D)(我不讨论它)3.参数说明:对图像X用wname小波基函数实现N层分解,这里的小波基函数应该根据实际情况选择,具体选择办法可以搜之或者hel

    2022年6月17日
    35
  • 一起学习Spring boot 2.1.X | 第五篇:Mybatis Druid 数据库(注解版)「建议收藏」

    一起学习Spring boot 2.1.X | 第五篇:Mybatis Druid 数据库(注解版)「建议收藏」运行展示正题Springboot:2.1.5RELEASE;数据库(Mysql、Oracle);Mybatis;阿里云的连接池:Druid;步骤1.POM依赖<!–MyBatis–><dependency><groupId>org.mybatis.spring.boot</groupId>…

    2022年7月23日
    17
  • vue中如何关闭eslint「建议收藏」

    vue中如何关闭eslint「建议收藏」1.在目录中新建vue.config.js2.在新建文件中输入module.exports={lintOnSave:false}就可以关闭啦~

    2022年10月8日
    4
  • 面试又挂了:大厂面试到底更看重学历还是技术?来看看大佬的说法

    面试又挂了:大厂面试到底更看重学历还是技术?来看看大佬的说法前言我是一个普通本科出身的Android程序员,我的学校也不过就是一个普通二本。嗯,我的学弟学妹们也是一样的,都是普通二本。但是和我不同的是,现在的社会越来越浮躁了,浮躁的让人沉不下心认真做事,让人忍不住去想各种有的没的。比如我的这些学弟学妹们。我已经不止一次收到来自他们的私信了,他们问的内容,无一不是表达对自己学历的自卑和对即将离开学校的自己的不自信,还有对面试被拒的伤心。千篇一律的问题,基本内容如下:面试挂了,大厂面试到底更看重学历还是技术?我这样的学历在求职中有什么需要注意点的点吗?

    2022年6月6日
    57
  • 谷歌的营销策略分析_反谷歌法

    谷歌的营销策略分析_反谷歌法谷歌YSlow准则YSlow可以对网站的页面进行分析,并告诉你为了提高网站性能,如何基于某些规则而进行优化。测试个人站点通过测试个人站点可以获得下面的数据23条准则MakefewerHT…

    2025年7月7日
    6

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号