English 中文(简体)
• 如何在MVC-Razor使用流体,而不使用javascript?
原标题:How to use rowspan in MVC-Razor, without javascript?

我怎么能够把囚室合并到一个桌子里,使用拉扎尔角的浏览器?

  • Without using javascript/jQuery.
  • The table s source is an IEnumerable.
  • Some of the items in the source will have the same value in a certain field and those are the one we want to merge in one cell.
  • We don t know how many times a given value is repeated.

由此形成的超文本应当如此:

<table>
    <tr>
        <td rowspan="2">Column 1 row 1</td>
        <td>Column 2 row 1</td>
    </tr>
    <tr>
        <td>Column 2 row 2</td>
    </tr>
    <tr>
        <td rowspan="3">Column 1 row 3</td>
        <td>Column 2 row 3</td>
    </tr>
    <tr>
        <td>Column 2 row 4</td>
    </tr>
    <tr>
        <td>Column 2 row 5</td>
    </tr>
</table>

EDIT增加数据来源和预期结果:

数据来源可能类似于具有类别的产品。 注

Categories

  • Electronics
  • Groceries

Products

  • Laptop (Electronics)
  • iPod (Electronics)
  • TV (Electronics)
  • Coffee (Groceries)
  • Cookies (Groceries)

The result

╔═════════════╦════════╗
║ Electronics ║ Laptop ║
║             ║ iPod   ║
║             ║ TV     ║
╠═════════════╬════════╣
║ Groceries   ║ Coffee ║
║             ║ Cookies║ 
╚═════════════╩════════╝

我所想的唯一方式是利用林克来计算其价值多少倍,但我想知道,有人是否有一个更好的解决办法。 感谢!

问题回答

类似情况。

<table>
    <tr>
        <th>Movie</th>
        <th>Person</th>
    </tr>

    @foreach (var byMovies in elements.GroupBy(x => x.Movie)
                                      .OrderBy(movie => movie.Key.Name))
    {
        var secondRowOrHigher = false;
        @:<tr>
        @:<td rowspan="@byMovies.Count()">@byMovies.Key.Name</td>

        foreach (var ticket in byMovies.OrderBy(x => x.Person.Name))
        {
            if (secondRowOrHigher)
            {
                @:<tr>
            }
            secondRowOrHigher = true;

            <td>@ticket.Person.Name</td>
            @:</tr>
        }
    }
</table>

仅了解情况

public class TicketInfo
{
    public Movie Movie { get; set; }
    public Person Person { get; set; }
}

public class Person
{
    public string Name { get; set; }
}

public class Movie
{
    public string Name { get; set; }
}




相关问题
Why isn t the table centered in Explorer?

This is a HTML email. I have two tables inside each other. One set to 100% and another inside 700px wide. This is the HTML: <table width="100%" border="0" align="center" cellspacing="0"> &...

How to switch from table to div for FORM layout?

I m noticing most folks are talking about using DIVs and CSS for label, textbox pairs. How would one convert a table such as: <table> <tr> <td><some Label1> </td&...

php: parsing table structure with SimpleXML

I m trying to read in an xml file that for some reason has been modeled in a table structure like so: <tr id="1"> <td name="Date">10/01/2009</td> <td name="PromoName">...

Exporting HTML Tables

How can I export an HTML table in my page as PDF and/or XLS? (preferably using JS (+jquery))

Table cells bad rendering with Google Chrome/Webkit

On the following code, COL1A and COL3A are not 50% height with Chrome or Webkit. It works fine with IE7 and Firefox. <table border="1"> <tr> <td height="100%">COL 1A</td>...

热门标签