Linq to sql making multiple calls in asp.net mvc 3
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 {
开发者_C百科 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.
Are you getting both a post and a get call to it?
try making
public ActionResult Delete(int id)
into
[HttpPost()]
public ActionResult Delete(int id)
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.
精彩评论