I am trying to generate list of skills with delete button in my view. Used a form tag to implement delete functionality using [HttpPost]. But problem is form is not getting generated properly. My table rows are not getting generated inside the form, but are being generated after form.
Following is my code in view.
@if (Model.Count() <= 0)
{
@Html.DisplayText("Skills not added, please add")
}
else
{
<br />
<table class="table table-hover">
<thead>
<tr>
<th>
Skill Category
</th>
<th>
Skill
</th>
<th>
</th>
</tr>
</thead>
<tbody>
@foreach (var fam in Model.ToList())
{
using(@Html.BeginForm("Delete", "Skill", new { id = @fam.SkillId }))
{
<tr>
<td>
@fam.Skill.SkillCategory.Description
</td>
<td>
@fam.Skill.Description
</td>
<td>
<input type="submit" value="Delete" class="btn btn-link">
</td>
</tr>
}
}
</tbody>
</table>
}
Following is the generated HTML.
<table class="table table-hover">
<thead>
<tr>
<th>
Skill Category
</th>
<th>
Skill
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<form action="/Skill/Delete/1" method="post"></form>
<tr>
<td>
Communication Skills
</td>
<td>
Verbal Communication
</td>
<td>
<input type="submit" value="Delete" class="btn btn-link">
</td>
</tr>
<form action="/Skill/Delete/53" method="post"></form>
<tr>
<td>
Personal Skills
</td>
<td>
Competitiveness
</td>
<td>
<input type="submit" value="Delete" class="btn btn-link">
</td>
</tr>
<form action="/Skill/Delete/163" method="post"></form>
<tr>
<td>
IT Skills
</td>
<td>
Java
</td>
<td>
<input type="submit" value="Delete" class="btn btn-link">
</td>
</tr>
<form action="/Skill/Delete/203" method="post"></form>
<tr>
<td>
Custom
</td>
<td>
DummySkill
</td>
<td>
<input type="submit" value="Delete" class="btn btn-link">
</td>
</tr>
</tbody>
</table>
From the above we can see that form is getting generated above my table rows, What could be the problem with my code?