Linq to sql 在 asp.net mvc 3 中进行多次调用
当我使用 linq to sql 更新记录时,我的 DeleteLesson()
方法被多次调用。
我的控制器看起来像这样:
public ActionResult Delete(int id)
{
deleteLesson(id);
return Content("<p style=color:red><strong>Deleted...</strong></p>");
}
public void deleteLesson(int id)
{
LLDataContext storeDB = new LLDataContext();
lesson lesson = (from l in storeDB.lessons
where l.lessonID == id
select l).Single();
lesson.statusID = DELETED;
lesson.dateDeleted = DateTime.Now;
lesson.deletedByUserID = getAppUserID();
try
{
storeDB.SubmitChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
storeDB.SubmitChanges();
}
}
我的视图看起来像这样
@Ajax.ActionLink("Delete", "Delete",
new { id = item.lessonID },
new AjaxOptions {
HttpMethod = "POST",
UpdateTargetId = @rowNumber.ToString()
}
)
有什么想法吗?
编辑
如果我在ajax选项中使用确认=“你想删除”
我将不得不单击“确定”三次。
When I am updating a record with linq to sql my DeleteLesson()
method is getting called multiple times.
My controller looks like this :
public ActionResult Delete(int id)
{
deleteLesson(id);
return Content("<p style=color:red><strong>Deleted...</strong></p>");
}
public void deleteLesson(int id)
{
LLDataContext storeDB = new LLDataContext();
lesson lesson = (from l in storeDB.lessons
where l.lessonID == id
select l).Single();
lesson.statusID = DELETED;
lesson.dateDeleted = DateTime.Now;
lesson.deletedByUserID = getAppUserID();
try
{
storeDB.SubmitChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
storeDB.SubmitChanges();
}
}
And my view looks like this
@Ajax.ActionLink("Delete", "Delete",
new { id = item.lessonID },
new AjaxOptions {
HttpMethod = "POST",
UpdateTargetId = @rowNumber.ToString()
}
)
Any Ideas?
EDIT
also if I use confirm = "Do you want to delete"
in ajax options I will have to click okay three times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否同时收到帖子和电话?
尝试将其
具体化为
http post IMO。您真的希望用户浏览到 /Lesson/Delete/5 并让它正常工作吗?我认为您只希望从显示他们要删除的课程的回发中处理此问题。
Are you getting both a post and a get call to it?
try making
into
specific to http post IMO. Do you really want users browsing to /Lesson/Delete/5 and have it work anyway? I'd think you only want this to handle from a postback where you're displaying the lesson they're going to delete.