javascript弹出消息不会出现删除

时间:2014-03-23 03:44:28

标签: javascript asp.net-mvc post

我正在学习MVC删除操作

https://www.youtube.com/watch?v=ItSA19x4RU0&list=PL6n9fhu94yhVm6S8I2xd6nYz2ZORd7X2v

观点:

@model IEnumerable<BusinessLayer.Employee>
@{
    ViewBag.Title = "Index";
}
<h2>
    Index</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Emp_id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Emp_name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Emp_Sal)
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model)
    {
        using (Html.BeginForm("Delete", "Employee", new { id = item.Emp_id }))
        {
            <tr> <td>
            @Html.DisplayFor(modelItem => item.Emp_id)
            </td> <td>
            @Html.DisplayFor(modelItem => item.Emp_name)
            </td> <td>
            @Html.DisplayFor(modelItem => item.Emp_Sal)
            </td> <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.Emp_id }) | <input type="submit"
        value="Delete" onclick="return Confirm("Are you Sure wanna Delete with ID =@item.Emp_id");"/> </td> </tr>
        }
    }
</table>

JavaScript代码中缺少什么?

请建议..

1 个答案:

答案 0 :(得分:1)

您正在执行return Confirm(),但window.confirm方法应使用小写“c”

尽管有许多更好的方法可以做你想做的事情,但问题的答案是将该行更改为return confirm(...

@Html.ActionLink("Edit", "Edit", new { id = item.Emp_id }) | <input type="submit"
    value="Delete" onclick="return confirm("Are you Sure wanna Delete with ID=@item.Emp_id");"/>