I have this Controller:
[HttpPost]
public JsonResult Execute(PaymentModel paymentModel){...}
this is the model
public class PaymentModel
{
[Required]
[DisplayName("Full name")]
public string FullName { get; set; }
...
}
this is the binding action
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
ModelBinders.Binders.Add(typeof(PaymentModel), new PaymentModelsBinding());
}
this is the binding inplementation
public class PaymentModelsBinding : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
//Cant get to here with the debugger
}
I dont know if that is relevant or not, but I am injecting using Ninject to the controller constructor.
Update
This is how the form is submitted:
$.ajax({
type: 'POST',
url: $("#form").attr("action"),
data: $("#form").serialize(),
success: function (json) {
...
},
dataType: "Json"
});
I want that to be restful, meaning I will to call it in every possible WEB way.
Browser Ajax, Browser Classic form submission, WebClient… and more.
Update
This is my ninject code:
kernel.Components.Add<IInjectionHeuristic, CustomInjectionHeuristic>();
kernel.Bind<IPaymentMethodFactory>().ToProvider<PaymentMethodFactoryProvider>().InSingletonScope();
kernel.Bind<IDefaultBll>().To<DefaultBll>().InSingletonScope();
kernel
.Bind<IDalSession>()
.ToProvider<HttpDalSessionProvider>()
.InRequestScope();
Thanks
Sorry, I can’t see anything wrong with your code. This should work. And as a proof of concept, here’s what you could try:
Define a view model:
A custom model binder:
HomeController:
A corresponding view (
~/Views/Home/Index.cshtml):And finally register the model binder in
Application_Start:Run the application in Debug mode, submit the form and the custom model binder gets hit.
So the question now becomes: what did you do differently?