【发布时间】:2014-06-14 07:41:51
【问题描述】:
我想使用 Post 方法删除员工的记录。我用按钮替换了 html.Actionlink。我还想在删除记录之前提示用户确认。
我写了以下代码:
<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的部分
-
看我更新了我的问题
-
你确定错误就在那一行吗?
-
是的先生,当我删除该javascript代码时,没有错误
-
也许当你拉出那个 onclick 时没有错误,但因为它看起来是有效的,可能之前的某些东西导致它在那里抛出错误。呈现的编辑和详细信息链接是什么样的?此外,您实际上是在您的 onclick 中呈现您的 @item.EmpId 还是它周围的引号阻止它被处理?
标签: javascript asp.net asp.net-mvc