MvcContrib CheckBoxList

Maybe someone can explain this behavior:

I use CheckBoxList from the latest version of MvcContrib. When my page loads for the first time - I just return my view

return View(Product.GetProduct(productId)); 

and everything seems beautiful. All simple html controls are populated successfully, including checkboxlist:

<%= this.CheckBoxList(model => model.Product.Statuses)
    .Options(Model.Statuses, model => model.Id, model => model.Name)
    .ItemFormat("{0}<br />")
%>

So, I have several buttons on this form, for example, the "Search" button (). I can search by productId and display it if something is found. Therefore, I pass productId to my controller, and this controller returns the view in the same way as the first time:

return View(Product.GetProduct(productId))

by the way, I use the same logic - anyway: the same view, the same controller, the same action ... nothing new. But in this case, I have this error message:

. : -. .

: System.FormatException: .

:

Line 268:                              <labe**strong text**l for="group<%=item.Value%>"><%=item.Text%></label><br />
Line 269:                          <% } %>--%>
Line 270:                          <%= this.CheckBoxList(model => model.Product.Statuses).Options(Model.Statuses, model => model.Id, model => model.Name).ItemFormat("{0}<br />")%>
Line 271:                        </div>
Line 272:                        </div>   

, view , , - , - , - .

. ?

+3
1

, CheckBoxList , , , ( "false", "true" ).

, , model = > model.id model = > "true", , :

 <%= this.CheckBoxList(model => model.Product.Statuses).Options(Model.Statuses, model => "true", model => model.Name).ItemFormat("{0}<br />")%>

, . - CheckBoxList ( model.Product.Statuses) ModelState, ModelState .

model.Product.Statuses ModelState . . .

if (!ModelState.IsValid)
{    
  ModelState.Remove(PropertyHelper<EmailModel>.GetProperty(x => x.Attachments).Name);
  ...

PropertyHelper PropertyInfo ?

mvccontrib: http://mvccontrib.codeplex.com/workitem/7071

+2

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


All Articles