Reputation: 115
I am having a value ["aaa","bbb","ccc"]
in column. I have to put each value in separate textbox without double quotes.
I have tried (in view):
<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>
and also
<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>
but it does not gives the exact solution what i need. How to do this.?
Upvotes: 0
Views: 1502
Reputation: 1579
You also do this, like the below code
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>
}
hope this helps
Upvotes: 3
Reputation: 554
Try this( get a counter used in differentiating the ids before you loop to create the textboxex )
@{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++
}
Upvotes: 0
Reputation: 540
try this
@{
foreach (var value in Model.editPeriodicTask.args.ToList().Split(','))
{
<td> @Html.TextBox("name", value, new {@id = "args", @class = "form-control-list"}) </td>
}
}
Upvotes: 0