The tables displayed in ASP. net mvc are not as easy as those in WebForm. I have summarized the following three methods: 1 JQERY + plug-in method. 2. display on the page through the Foreach loop. 3. Use open-source controls, such as MvcContrib. MvcContrib is a well-known control, which is powerful enough to function overnight, including support for AOP. The following is a brief introduction of MvcContrib's first use experience. MvcContrib can be downloaded from CodePlex.
There are some heroes on the Internet to introduce the use of MvcContrib. However, due to version issues, the usage of MvcContrib is not the same as that of laruence. So I will record my usage experience for anyone who needs it. Of course, after all, I have just started to use it, but I still don't know much about it. I hope you will have the opportunity to learn from each other.
First, let's talk about the MvcContrib version 2.0.96.0 I used.
If you are familiar with the WebForm mode or MVC mode, you must know that there is a Pages node in the System. Web configuration section. This node is used to configure all pages of the project, including the explicit space. First, configure in the Web. Config file. The following namespaces need to be introduced:
<add namespace="MvcContrib.UI"/><add namespace="MvcContrib.UI.Html"/><add namespace="MvcContrib"/><add namespace="MvcContrib.UI.Grid"/>
On the page, you can use <% Html. Grid %>. Grid is a generic method. You need to specify a generic type to use this type for table display. Then you can directly give the data source and then output it. For example, <% Html. Grid <Demo. Models. Student> (ViewData. Model). AutoGenerateColumns <Demo. Models. Student () %>. You can use the AutoGenerateColumns generic method to output data. However, the output is the entire data table returned from the Controller.
Of course, it is also feasible to make the data returned by the Controller layer have the output of the selected row. The procedure is as follows:
<% Html. grid <Demo. models. student> (ViewData. model ). columns (cols => {cols. for (s => s. name); cols. for (s => s. address, "Address") ;}); %>
With the Lambda expression above, you can output the specified data column. You can also set the style of the column. For example:
<% Html. grid <Demo. models. student> (ViewData. model ). columns (cols => {cols. for (s => s. name ). attributes (new Hash (@ class => "grid "). add <int> ("cellpadding", 2 ). add <int> ("cellspacing", 0); cols. for (s => s. address, "Address "). doNotEncode ();}). empty ("no data "). headerRowAttributes (new Hash (Style => "text-align: center; font: bold 13px/20px Verdana;"); %>
Attributes is the style of the column, DoNotEncode is the HTML code for the column display, Empty indicates no number
<Br> HeaderRowAttributes sets the Header style.
In earlier versions, the usage of Columns is slightly different from that of the current version. in earlier versions, Columns is used as the second parameter of the Grid generic method.
. In this version, the Gird wildcard </strong> <br> <strong> method has only one parameter, but there are two parameters.
Type, 1: String Of the Key name in ViewData. 2. IEnumerable <> type data
Source
MvcContrib uses more than this. He also includes creating a Form
Some verification settings, perform Route, and extend the Controller function. In short, it <br> is a powerful open-source control. I will introduce some experiences later.