[英]ASP.NET Core MVC button visibility
Hiding multiple buttons I previously added to table cells.隐藏我之前添加到表格单元格的多个按钮。 Is it possible to sequentially make it visible with a single button control?
是否可以使用单个按钮控件顺序使其可见? How can I do this with c#?
如何使用 c# 做到这一点?
There are educational contents such as layout, html, css on the web but I could not find anything related to what I wanted to do. web 上有布局、html、css 等教育内容,但我找不到与我想做的相关的任何内容。 How can I solve this problem?
我怎么解决这个问题?
If you want to do it with c#,when click add button,you need to pass the data you want to pass the amount you want to show to action.Here is a demo:如果你想用 c# 来做,当点击添加按钮时,你需要传递你想要传递的数据来传递你想要显示的数量。这是一个演示:
View(TestTable.cshtml):查看(TestTable.cshtml):
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
<tbody>
@if (Model.Amount > 0)
{
var count = 0;
@for (var i = 0; i < Model.Amount / 5 + 1; i++)
{
<tr>
@for (var j = 0; j < 5; j++)
{
count++;
if (count <=Model.Amount&&count<=Model.Buttons.Count)
{
<th><button>@Model.Buttons[5 * i + j]</button></th>
}
else
{
break;
}
}
</tr>
}
}
</tbody>
</table>
<form method="post">
<input hidden name="Amount" value="@Model.Amount">
<input hidden name="Add" value="1">
<button>Add</button>
</form>
Action:行动:
public IActionResult TestTable(TableModel t)
{
List<string> l = new List<string> { "b0", "b1", "b2", "b3", "b4", "b5" };
TableModel table = new TableModel { Buttons = l ,Amount=0,Add=0};
if (t.Add == 1 && t.Amount >= 0) {
table.Amount = ++t.Amount;
}
return View(table);
}
Model: Model:
public class TableModel {
public List<string> Buttons { get; set; }
public int Amount { get; set; }
public int Add { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.