Single view for all the Grids in MVC - c#

I have a requirement like display many of collections in a HTML table format like mentioned below.
<table>
<thead>
<tr>
<th>Column 1 Heading</th>
<!--More column headings-->
</tr>
</thead>
<tbody>
#foreach (var item in Model.MyCollection)
{
<tr>
<td>#item.PropertyName</td>
<!--More properties-->
</tr>
}
</tbody>
<!--Add footer for totals-->
</table>
I will not specify the view model property names explicitly. I wanted to pass any type of collections to view that will need to generate a HTML table for me.
Please suggest better way of doing it.

Related

How to insert different images in ASP.NET MVC while using a foreachloop and a db

<table class ="table" cellpadding="0" cellspacing="0">
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Seafood</th>
<th>Has Gluten</th>
<th>Picture</th>
</tr>
#foreach (var items in #Model)
{
<tr>
<td>#items.ItemName</td>
<td>#items.Price</td>
<td>#items.IsSeafood</td>
<td>#items.HasGluten</td>
</tr>
}
I am currently learning how to develop using ASP.NET MVC.
I am trying to insert different images for each of my items. My foreach loop creates the table and items from a mysql database. I want to add the pictures next to the tables unless I'm unable to with the code I have.
You can use an <img src=""/> tag inside your last <td> to embed the image directly into the html.
Something like this, depending on how your image is stored.
<td><img src="#items.Url"/></td>

How to use ng-repeat inside <td> tags without changing the table design

I have nested 3 lists. And I want those data to display in a table. When I'm trying like this,
<tbody>
<tr ng-repeat-start="item in searchResultList" >
<td>{{item.Group.AuditDate | date:"MM/dd/yyyy h:mma"}}</td>
<td>{{item.Group.User}}</td>
</tr>
<tr ng-repeat-start="x in item.DeviceList.DescriptionList">
<td></td>
<td></td>
<td>{{x.Description}}</td>
</tr>
<tr ng-repeat-end ng-repeat="y in x.ChangesList">
<td></td>
<td></td>
<td></td>
<td>{{y.ChangeFrom}}</td>
<td>{{y.ChangeTo}}</td>
</tr>
<tr ng-repeat-end></tr>
</tbody>
Then It displays like this.
But I don't want to repeat lines when each data repeat. I want to display all the 1st data in a straight line,and when description repeat for the same date and user, then it should be in a new line. I want an alignment like this.
Parse your data in below format in the controller and then use ng-repeat to display.
[{'08/11/2016 5:56PM', 'Administrator','Aaa','b','c'}, {'', '','','d','f'},{'','','Bbb','b','c'},{'10/16/2015 11:41AM','Tharuka','Ccc','c','d'}]

Fix header of table without thead with scroll bar

I have the following structure:
<div>
<table>
<tbody>
<tr>
<th>1</th>
<!--and some columns-->
</tr>
<!--some datarows-->
<tr>
<td></td> <!--a lot of columns-->
</tr>
</tbody>
<table>
</div>
I want to fix the header.
I got number of links but all they having thead in structure as I am table control in C# can't have control over the structure and also I cannot re-write html markup dynamically (not allowed).
Now I can easily fix the tableheaderrow with style
position : fixed
But table contains scroll bars so the header comes outside the panel.
Any suggestion will be highly appreciated.

Take HTML Table and put into custom List

I have an html table I need to query, get the contents and then act on that.
this the table
<table>
<thead>
<tr>
<th>Version</th>
<th>Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.0.1.1</td>
<td>86</td>
</tr>
<tr>
<td>1.0.0.1</td>
<td>65</td>
</tr>
<tr>
<td>1.0.1.0</td>
<td>28</td>
</tr>
<tr>
<td>1.0.0.0</td>
<td>1</td>
</tr>
</tbody>
</table>
I'm getting that by passing the WebResponse through a regex expression.
What is the best way to get this into some data structure in C# so that I can query on the Version and Usage.. Baically have a List of class Foo.
Foo()
{
Version {get; set;}
Usage {get; set;}
}
Along those lines.
Thanks for your help
The best tool I've found for parsing HTML is the Html Agility Pack library. It is a fairly easy to use library, and will handle improperly formatted markup fairly well. You'll have to do the footwork of getting the data out from the library and into your own structures, but it'll make it easy for getting at the data.

How do I display a datatable in asp.net mvc 2?

I am running a dynamically built SQL statement and putting the results in a datatable. I then need to display these results as a table in a partial view. I would normally create a List<> object and strongly type it to the page, but in this case I do not know what the final sql will be, since it is built by the user at run time.
So, how can I display the data in a datatable when I do not know what is in it? Also is there a better way to do this than in a datatable?
Thanks
As you are displaying tablular data, you should use an html table to do the job. Dismissile's answer only displays one column of the table. The more generic answer can be found in the following SO question:
Displaying standard DataTables in MVC
The bit that concerns you is, with the model strongly typed as a DataTable:
<table border="1">
<thead>
<tr>
<%foreach (System.Data.DataColumn col in Model.Columns) { %>
<th><%: col.Caption %></th>
<%} %>
</tr>
</thead>
<tbody>
<% foreach(System.Data.DataRow row in Model.Rows) { %>
<tr>
<% foreach (var cell in row.ItemArray) {%>
<td><%: cell.ToString() %></td>
<%} %>
</tr>
<%} %>
</tbody>
</table>
EDIT
Edited to encode the content of the datable. As using mvc 2 (according to the tag), then Html.Encode not required, just the <%: notation that is available in mvc 2.

Categories

Resources