开发者

Model binding in MVC3 application passing null to action parameter under Mono

A simple controller action that is posted to which takes a model used by the view's form isn't being bound to the form fields when running under Mono 2.10.1. Under MS.NET the same code executes as expected with the model populated with the co开发者_如何学编程rresponding form values.

The controller action is defined as:

[HttpPost]
public ActionResult Login(LoginModel login, string returnUrl)
{

The first parameter login is null when the form is submitted on Mono, and fully populated with the login form fields under MS.NET.

The form fields are accessible via the Request.Form collection (ie Request.Form["UserName"]) under Mono, so it seems to just be the binding that isn't working.

This used to be an MVC2 app - anyone experienced something similar?


I tracked this down to a custom data annotations model validation provider that we register to handle our own way of localizing error messages such as Required and Display Name on model properties.

Commenting out the following line:

DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(LocalizedRequiredAttribute), typeof(RequiredAttributeAdapter));

From global asax fixes the issue, and the custom model validator still works - looks like it was a hang over from MVC2 days.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜