Answered by:
Razor How to rowspan?

Question
-
User-1104215994 posted
Hello,
I have JSON data as follows. According to line <g class="gr_ gr_6 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="6" data-gr-id="6">numbers</g> I would like to display shelves in <g class="gr_ gr_7 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="7" data-gr-id="7">rowspan</g> on my View.
{ "ImageUrl": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL", "lines":[ { "number":0, "products":[ { "id":1, "name":"Zero 330ml", "count":5, "master_count":5, "count_average": "100%", "position_average": "100%" },{ "id":2, "name":"Classic 330ml", "count":10, "master_count":7, "count_average": "70%", "position_average": "100%" },{ "id":3, "name":"Light 330ml", "count":4, "master_count":4, "count_average": "100%", "position_average": "100%" } ], "products_position_average":"80%", "line_average":"90%" },{ "number":1, "products":[ { "id":1, "name":"Zero 330ml", "count":5, "master_count":5, "count_average": "100%", "position_average": "100%" },{ "id":2, "name":"Classic 330ml", "count":10, "master_count":7, "count_average": "70%", "position_average": "100%" } ], "products_position_average":"0%", "line_average":"0%" },{ "number":2, "products":[], "products_position_average":"0%", "line_average":"0%" } ] }
Here is my View -only table portion- without shelves(line number):
<div class="col-sm-3 c217"> @if (Model.lines != null) { <h3 class="center">Results</h3> <table class="table table-bordered table-responsive table-hover" style="font-size: 11px !important;"> <thead> <tr> <th>Name </th> <th>Master</th> <th>Count </th> <th>Average</th> <th>Position</th> </tr> </thead> @for (int i = 0; i < Model.lines.Count(); ++i) { for (int k = 0; k < Model.lines[i].products.Count(); ++k) { if (Model.lines[k].products != null) { <tr> <td> @Model.lines[i].products[k].name </td> <td> @Model.lines[i].products[k].master_count </td> <td> @Model.lines[i].products[k].count </td> <td> @Model.lines[i].products[k].count_average </td> @if ( @Model.lines[i].products[k].position_average == "100%"){ <td> OK </td> }else{ <td> X </td> } </tr> } } if (Model.lines[i].products.Length > 0) { <tr style="font-weight:bold"> <td> Total </td> <td> @Model.lines[i].products.Sum(m => m.master_count) </td> <td> @Model.lines[i].products.Sum(m => m.count) </td> <td> @Convert.ToInt32((@Model.lines[i].products.Sum(m => m.master_count) * 100.0 / @Model.lines[i].products.Sum(m => m.count)))% </td> </tr> } } <tr style="font-weight:bold"> <td> Cabinet </td> <td> @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.master_count)) </td> <td> @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.count)) </td> <td> @Convert.ToInt32(@Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.master_count)) * 100.0 / @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.count)))% </td> </tr> </table> } </div>
Here is how I want my table View
Best Regards.
Thursday, January 10, 2019 5:59 AM
Answers
-
User1520731567 posted
Hi cenk1536,
According to your code and picture,I try to modify your code,please refer to it:
@model Project1.Controllers.HomeController.JsonResponse @{ ViewBag.Title = "JObjectParse"; } <h2>JObjectParse</h2> <div class="col-sm-3 c217"> @if (Model.lines != null) { <h3 class="center">Results</h3> <table class="table table-bordered table-responsive table-hover" style="font-size: 11px !important;"> <thead> <tr> <th></th> <th>Name </th> <th>Master</th> <th>Count </th> <th>Average</th> <th>Position</th> </tr> </thead> @for (int i = 0; i < Model.lines.Count(); ++i) { for (int k = 0; k < Model.lines[i].products.Count(); ++k) { if (Model.lines[k].products != null) { <tr> @if (k == 0) { <td rowspan="@Model.lines[i].products.Count()" align="center"> @i .shelf </td> } <td> @Model.lines[i].products[k].name </td> <td> @Model.lines[i].products[k].master_count </td> <td> @Model.lines[i].products[k].count </td> <td> @Model.lines[i].products[k].count_average </td> @if (@Model.lines[i].products[k].position_average == "100%") { <td> OK </td> } else { <td> X </td> } </tr> } } @*if (Model.lines[i].products.Length > 0) { <tr style="font-weight:bold"> <td> Total </td> <td> @Model.lines[i].products.Sum(m => m.master_count) </td> <td> @Model.lines[i].products.Sum(m => m.count) </td> <td> @Convert.ToInt32((@Model.lines[i].products.Sum(m => m.master_count) * 100.0 / @Model.lines[i].products.Sum(m => m.count)))% </td> </tr> }*@ } <tr style="font-weight:bold"> <td colspan="2"> Cabinet </td> <td> @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.master_count)) </td> <td> @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.count)) </td> <td> @Convert.ToInt32(@Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.master_count)) * 100.0 / @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.count)))% </td> </tr> </table> } </div>
How it works:
Best Regards.
Yuki Tao
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 10, 2019 8:50 AM
All replies
-
User1520731567 posted
Hi cenk1536,
According to your code and picture,I try to modify your code,please refer to it:
@model Project1.Controllers.HomeController.JsonResponse @{ ViewBag.Title = "JObjectParse"; } <h2>JObjectParse</h2> <div class="col-sm-3 c217"> @if (Model.lines != null) { <h3 class="center">Results</h3> <table class="table table-bordered table-responsive table-hover" style="font-size: 11px !important;"> <thead> <tr> <th></th> <th>Name </th> <th>Master</th> <th>Count </th> <th>Average</th> <th>Position</th> </tr> </thead> @for (int i = 0; i < Model.lines.Count(); ++i) { for (int k = 0; k < Model.lines[i].products.Count(); ++k) { if (Model.lines[k].products != null) { <tr> @if (k == 0) { <td rowspan="@Model.lines[i].products.Count()" align="center"> @i .shelf </td> } <td> @Model.lines[i].products[k].name </td> <td> @Model.lines[i].products[k].master_count </td> <td> @Model.lines[i].products[k].count </td> <td> @Model.lines[i].products[k].count_average </td> @if (@Model.lines[i].products[k].position_average == "100%") { <td> OK </td> } else { <td> X </td> } </tr> } } @*if (Model.lines[i].products.Length > 0) { <tr style="font-weight:bold"> <td> Total </td> <td> @Model.lines[i].products.Sum(m => m.master_count) </td> <td> @Model.lines[i].products.Sum(m => m.count) </td> <td> @Convert.ToInt32((@Model.lines[i].products.Sum(m => m.master_count) * 100.0 / @Model.lines[i].products.Sum(m => m.count)))% </td> </tr> }*@ } <tr style="font-weight:bold"> <td colspan="2"> Cabinet </td> <td> @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.master_count)) </td> <td> @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.count)) </td> <td> @Convert.ToInt32(@Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.master_count)) * 100.0 / @Model.lines.Select(m => m.products).Sum(m => m.Sum(p => p.count)))% </td> </tr> </table> } </div>
How it works:
Best Regards.
Yuki Tao
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 10, 2019 8:50 AM -
User-1104215994 posted
<td rowspan="@Model.lines[i].products.Count()" align="center"> @i .shelf </td>
Changed to this:
<td rowspan="@(Model.lines[i].products.Count()+1)" align="center"> @(i+1) </td>
Thursday, January 10, 2019 2:15 PM