MVC 3에 발사하지 :IModelBinder 내가이 컨트롤러가
[HttpPost]
public JsonResult Execute(PaymentModel paymentModel){...}
이 모델입니다
public class PaymentModel
{
[Required]
[DisplayName("Full name")]
public string FullName { get; set; }
...
}
이 이것을 inplementation
결합되어있는 바인딩 작업을protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
ModelBinders.Binders.Add(typeof(PaymentModel), new PaymentModelsBinding());
}
입니다
public class PaymentModelsBinding : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
//Cant get to here with the debugger
}
관련이 있는지 없는지는 잘 모르겠지만 Ninject를 컨트롤러 생성자에 주입하고 있습니다.
업데이트 이 양식을 제출하는 방법입니다
$.ajax({
type: 'POST',
url: $("#form").attr("action"),
data: $("#form").serialize(),
success: function (json) {
...
},
dataType: "Json"
});
내가 그 편안한되고 싶어요, 모든 가능한 웹 방식으로 전화를 나는 것 의미한다.
브라우저 Ajax, 브라우저 기본 양식 제출, WebClient ... 등.
업데이트 이 내 Ninject에 코드입니다 :
kernel.Components.Add<IInjectionHeuristic, CustomInjectionHeuristic>();
kernel.Bind<IPaymentMethodFactory>().ToProvider<PaymentMethodFactoryProvider>().InSingletonScope();
kernel.Bind<IDefaultBll>().To<DefaultBll>().InSingletonScope();
kernel
.Bind<IDalSession>()
.ToProvider<HttpDalSessionProvider>()
.InRequestScope();
감사
이 컨트롤러 동작을 어떻게 부르겠습니까? 액션이 호출 될 때 모델 바인더가 호출됩니다. –
@DarinDimitrov - 웹 양식을 통해 전화하고 있습니다. 'Execute (PaymentModel paymentModel)'을 호출 할 수 있지만 그 전에는 모델을 호출 할 수 없습니다. – SexyMF
어떻게 부르시겠습니까? 제출 된보기 내부에 HTML 양식이 있습니까? 아니면 AJAX를 사용하고 있습니까? 아니면 다른 방법으로이 작업을 호출 할 수 있습니까? –