I show a list of files and allow the user to remove from the list. The delete button makes an ajax call to the controller to launch the "Delete" action. However, the delete action is never called. I get a warning defined in AjaxOptions. For what it was worth it, I worked using the WebForms engine and simply transferred it to Razor. This is also the first time I've used the Neighborhoods. If I call the "Delete" action directly, it works. Is this a routing problem?
Here is the code
public EmptyResult Delete(string fileName) { if (fileName.IsNullOrEmpty()) return null; var model = new Models.BenefitBookletModel(); model.DeleteBooklet(fileName); return null; }
Here is the mark
@Ajax.ActionLink("test", "Delete", new { fileName = item.FileName }, new AjaxOptions { Confirm = "Are you sure you want to delete " + item.FileName + "?", OnComplete = "function(){deleteComplete('" + item.jsReferenceableFileName + "')}", HttpMethod = "DELETE", OnFailure = "function(){alert('Could not delete file');}" }, new { @class = "DeleteButton" } )
Here are my RegisterRoutes
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute("SubscriberAll","subscriber/{id}",new { controller = "Subscriber", action = "ShowAll" },new { id = @"\d+" } ); routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
Routes from the registration area
context.MapRoute("Marketing_default","Marketing/{controller}/{action}/{id}",new { action = "Index", id = UrlParameter.Optional }
Here is the markup created
<a href="/Marketing/BenefitBooklet/Delete?fileName=MyFileName.pdf" data-ajax-method="GET" data-ajax-failure="function(){alert('Could not delete file');}" data-ajax-confirm="Are you sure you want to delete MyFileName.pdf?" data-ajax-complete="function(){deleteComplete('MyFileName.pdf')}" data-ajax="true" class="DeleteButton"> </a>