我在列中有一个值["aaa","bbb","ccc"]
。我必须将每个值放在单独的文本框中,而不使用双引号。
我试过(在视野中):
<td>@Html.TextBoxFor(m => (m.editPeriodicTask.args[0]), new { @id = "args0", @class = "form-control-list" })</td>
<td>@Html.TextBoxFor(m => (m.editPeriodicTask.args[1]), new { @id = "args1", @class = "form-control-list" })</td>
<td>@Html.TextBoxFor(m => (m.editPeriodicTask.args[2]), new { @id = "args2", @class = "form-control-list" })</td>
以及
<td>@Html.TextBoxFor(m => (m.editPeriodicTask.args.split(',')[0]), new { @id = "args0", @class = "form-control-list" })</td>
<td>@Html.TextBoxFor(m => (m.editPeriodicTask.args.split(',')[1]), new { @id = "args1", @class = "form-control-list" })</td>
<td>@Html.TextBoxFor(m => (m.editPeriodicTask.args.split(',')[2]), new { @id = "args2", @class = "form-control-list" })</td>
但它没有给出我需要的确切解决方案。 这该怎么做。?
答案 0 :(得分:3)
您也可以这样做,如下面的代码
var value = ["aaa","bbb","ccc"];
var data1 = value.Replace("[","").Replace("]","");
var item = data1.Split(',');
for(var i = 0; i < item.length; i++)
{
var data = item[i].Replace("\"","");
<td>@Html.TextBoxFor(m => m.editPeriodicTask.args, new { @id = "args" + i, @class = "form-control-list", @Value = data})</td>
}
希望这会有所帮助
答案 1 :(得分:0)
试试这个
@{
foreach (var value in Model.editPeriodicTask.args.ToList().Split(','))
{
<td> @Html.TextBox("name", value, new {@id = "args", @class = "form-control-list"}) </td>
}
}
答案 2 :(得分:0)
试试这个(在循环创建textboxex之前获取用于区分id的计数器)
@{int count = 0;}
@foreach (var value in Model.editPeriodicTask.args.ToList().Split(','))
{
<td> @Html.TextBox("name", value, new {@id = "args"+count, @class = "form-control-list"}) </td>
count++
}