어리석은 문제를 해결하기 위해 쿼리 문자열에 값을 추가해야하며 (자바 스크립트에서 해당 값을 추가해야 함) 서버에이 값이 있는지 테스트해야합니다. (이는 아약스 또는 iframe에서 발생할 수 있으므로 헤더 잠재력이 없습니다. , 슬프게도, 내 <form>
요소에 값을 추가하는 것을 피하려고합니다. 이를 위해, 나는이 작은 조각을 고안했습니다, 그리고 나는 "세터"블록을 넣어 어디 잘 모르겠어요 : 나는 (A)
그것을 설정 한 후 클라이언트가 여전히에 시간이처럼 보인다면MVC 반환 contentType에 대한 속성을 사용하려면 OnResultExecuting 또는 OnResultExecuted에서 수행하는 것이 더 낫지 않습니까?
using System.Web.Mvc;
namespace Company.Client.Framework.Mvc
{
class CreateFormDialogResponseAttribute : ActionFilterAttribute
{
private bool SetContentType { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
SetContentType = !filterContext.HttpContext.Request.Params["FormDialogRequest"].IsEmpty();
base.OnActionExecuting(filterContext);
}
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
//do I set it here? (A)
if (SetContentType)
filterContext.HttpContext.Response.ContentType = "text/json";
base.OnResultExecuting(filterContext);
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
//do I set it here? (B)
if (SetContentType)
filterContext.HttpContext.Response.ContentType = "text/json";
base.OnResultExecuted(filterContext);
}
}
}
을 필요한 경우 속성을 "대체"하십시오. (B)
은 처럼 보입니다. "당신이하고 싶은 생각이 마음에 들지 않습니다" 포지션. 그게 정확한 이해일까요?