Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC4 Model Binding

Does anyone know when model binding takes place in the request lifecycle? The reason I ask is that I'm running into some localization issues.

Does Model Binding happen before OnActionExecuting is executed?

Currently I set the current culture in a global action filters OnActionExecuting method but this isn't being respected when performing model binding. The request is a POST.

Thanks in advance.

like image 543
Tom Miller Avatar asked Oct 09 '12 09:10

Tom Miller


People also ask

What is model binding in asp net core?

Model binding allows controller actions to work directly with model types (passed in as method arguments), rather than HTTP requests. Mapping between incoming request data and application models is handled by model binders.

How do you bind data in Razor view?

Using the Razor syntax instead of plain HTML it is very easy to construct and bind your form elements to the corresponding data. In this case the label will show the value of the Display attribute in the User class and the values of the user will be filled in the textboxes.

Is MVC two way data binding?

So the two-way data binding means we can perform both read and write operations.


1 Answers

I would suggest you to set the culture at a very earlier point not in action filter. In my current project I've set the culture in the Application_AcquireRequestState event in Global.asax.cs. You can try that.

protected void Application_AcquireRequestState(Object sender, EventArgs e)
{
   // set the culture
}
like image 157
VJAI Avatar answered Sep 24 '22 08:09

VJAI