I have a table with each row row containing a task. I would like to have a column with links allowing the user to toggle the completed status of the task.
As this is changing data, I only allow the change Action to be called from a Post. I.e. I have an ActionFilter of [AcceptVerbs(HttpVerbs.Post)].
This in turn requires a form in each row of the table. This works, but has an ugly button everywhere.
I think I could achive the data security I am looking for, by doing using an Ajax.ActionLink, and checking in the Action to make sure it is an ajax call.
Currently I have something like
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ToggleToDoItem(int Id, int? page)
{
//update completed status
...
return ToDoItemsPv(null, page);
}
I am looking to change it to public ActionResult ToggleToDoItem(int Id, int? page) { if (HttpContext.Request.IsAjaxRequest()) { //update completed status ...
return ToDoItemsPv(null, page);
}
else
{
return Redirect(some error page);
}
}
The main thing I am trying to achive, is replacing the form buttons with links so it looks better.
Is this safe? Is it good practise?
Thanks