ASP.Net MVC DefaultModelBinder does not bind properties on POST

I ran into a really strange problem that made me smoke.

I have a fairly simple scenario where I have a strongly typed view that is correctly populated from the controller in GET, but then when it POSTS forms to the controller, Reqeust is full of all the correct values ​​and right-click names for the standard binder to correctly fill one of of my model objects, and DMB creates the correct option, but it never fills any properties, they are all in the default state.

This worked before then, the only changes I can think of are that I tried the user modelbinder module (then uninstalled it, double checked it to make sure that I am not using it yet), and I reorganized the model to a base class with some details.

Any thoughts?

+3
source share
4 answers

Got it. The model was reorganized in such a way that, of course, affected the ability of the binder model to fill it.

0
source

A very similar scenario - that DefaultModelBinder - essentially - is not required for your model, accept if you pass an object to the linked model with the same name as one of its properties:

Model

Public Property ArbitraryName1 As Integer
Public Property Answer As String
Public Property ArbitraryName2 As Boolean

View

<p/> ... @Model.ArbitraryName1
<p/> Answer: @Html.TextBoxFor(Function(model) model.Answer)
<p/> ... @Html.CheckBoxFor(Function(model) model.ArbitraryName2)

controller

<HttpPost()>
Function Index(answer As Model) As ActionResult
  ' answer is Nothing
End Function

(using ASP.NET MVC 3)

+3
source

. , , → , , .

0

, . , ( , " " ), , , , . , "" , .

0
source

Source: https://habr.com/ru/post/1709826/


All Articles