0
我想使用Post方法刪除員工的記錄。我用按鈕替換了html.Actionlink。我還想在刪除記錄之前提示用戶進行確認。
我已經寫了下面的代碼:JavaScript代碼中的MVC錯誤
<input value="Delete" type="submit" onclick="return confirm('Are you sure want to delete ID = @item.EmpId');"/>
此行是顯示錯誤「unterminated string constant
」, 什麼是錯的代碼?
我的完整視圖代碼
<table border="1">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Gender)
</th>
<th>
@Html.DisplayNameFor(model => model.City)
</th>
<th>
@Html.DisplayNameFor(model => model.DID)
</th>
<th>Action
</th>
</tr>
@foreach (var item in Model)
{
using (Html.BeginForm("Delete", "Employee",new{id=item.EmpId}))
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Gender)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@Html.DisplayFor(modelItem => item.DID)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.EmpId }) |
@Html.ActionLink("Details", "Details", new { id = item.EmpId }) |
<input value="Delete" type="submit" onclick="return confirm('Are you sure want to delete ID = @item.EmpId');"/>
</td>
</tr>
}
}
</table>
你能發佈你的視圖的完整代碼嗎?至少@item被定義的部分 – thepirat000
看到我已經更新了我的問題 –
你確定錯誤在那一行嗎? – thepirat000