我有一个财务总监:
[HttpPost]
public JsonResult Execute(PaymentModel paymentModel){...}这就是模型
public class PaymentModel
{
[Required]
[DisplayName("Full name")]
public string FullName { get; set; }
...
}这是绑定操作
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
}我不知道这是否相关,但我正在向控制器构造函数中注入与否。
更新--以下是表单的提交方式:
$.ajax({
type: 'POST',
url: $("#form").attr("action"),
data: $("#form").serialize(),
success: function (json) {
...
},
dataType: "Json"
});我希望这是restful,这意味着我将以每一种可能的WEB方式调用它。
浏览器Ajax,浏览器经典表单提交,WebClient还有更多。
更新--这是我的代码:
kernel.Components.Add<IInjectionHeuristic, CustomInjectionHeuristic>();
kernel.Bind<IPaymentMethodFactory>().ToProvider<PaymentMethodFactoryProvider>().InSingletonScope();
kernel.Bind<IDefaultBll>().To<DefaultBll>().InSingletonScope();
kernel
.Bind<IDalSession>()
.ToProvider<HttpDalSessionProvider>()
.InRequestScope();谢谢
发布于 2013-01-13 12:26:40
抱歉,我看不出你的密码有什么问题。这应该能行。作为概念的证明,以下是你可以尝试的:
~/Views/Home/Index.cshtml):
@model PaymentModel @url (Html.BeginForm(null,null,FormMethod.Post,new { id = "form“})) { @Html.EditorFor(x => x.FullName) OK }$(‘#form’).submit(函数() { $.ajax({ type: this.method,url: this.action,data:$(this).serialize(),成功:函数(json) { });返回false;});Application_Start中注册模型绑定:
ModelBinders.Binders.Add(typeof(PaymentModel),新PaymentModelsBinding();所以现在的问题是:你做了什么不同的事情?
https://stackoverflow.com/questions/14302549
复制相似问题