파일 목록을 표시하고 사용자가 목록에서 삭제할 수 있도록합니다. 삭제 단추는 '삭제'작업을 실행하기 위해 컨트롤러에 대한 아약스 호출을 수행합니다. 그러나 삭제 액션은 호출되지 않습니다. AjaxOptions에 정의 된 확인 경고가 나타납니다. 가치가있는 부분에 대해 WebForms 엔진을 사용하여 작업하고 Razor로 옮겼습니다. 또한, 제가 Area를 처음 사용했습니다. 삭제 작업을 직접 호출하면 작동합니다. 라우팅 문제입니까? 여기 Ajax.ActionLink가 컨트롤러 액션을 호출하지 않습니다.
다음은 지역 등록에서 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 });
경로를 여기
@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" }
)
까지 표시가되어있어 내 RegisterRoutes
public EmptyResult Delete(string fileName)
{
if (fileName.IsNullOrEmpty()) return null;
var model = new Models.BenefitBookletModel();
model.DeleteBooklet(fileName);
return null;
}
뒤에 코드의
context.MapRoute("Marketing_default","Marketing/{controller}/{action}/{id}",new { action = "Index", id = UrlParameter.Optional }
다음은 DELETE로 동작 링크의 HttpMethod를 정의하지만 GET 받아에만 아마 방법
<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>
은 Global.asax에에서 정보를 추가하십시오. – Kath
Delete 메서드는 뷰를 렌더링 한 컨트롤러와 같은 컨트롤러에 있습니까? 그렇지 않으면 ActionLink (AjaxHelper, String, String, String, Object, AjaxOptions) 오버로드를 사용하여 컨트롤러를 정의해야합니다. –
예, 둘 다 동일한 컨트롤러에 있습니다. –