views:

38

answers:

1

I'm building a form with many panels and many controls (both inside and outside the panels). Panels and controls have to be enabled/disabled for edition (and probably disabled for edition with the last selected value) depending on model state, other panel's state and their own business rules validation. Until now, we have created many panels with the same controls (many .aspx) to add them whenever we want to according model state and business conditions (etc.). I think it can be done in a better way... (ie. using ModelState and manipulating its keys or disabling form validation based on a criteria....). So:

  1. Is it possible to control which fields in the model are going to be validated with each post?
  2. Can view controls be disabled (both for edition and validation) based on model's state?
  3. If the answer is "NO" for 1 and 2, how would you enable/disable controls using the model's state?
A: 

You can control whether fields are displayed and/or validated based on the Model's state in a manner like so:

<%if (Model.SomeProperty==someValue){%>
   <%: Html.TextBoxFor(blah=> blah....)...%>
   <%if (Model.OtherProperty==otherValue){%>
      <%: Html.Validator...%>
   <%}%>
<%}%>
Andrew Barber
The above assumes, of course, the Web Forms View Engine
Andrew Barber