We are in process of upgrading from Telerik Q3 2010 asp.net mvc extensions to Q1 2011. Previously, in grid editi开发者_开发技巧ng disabled values were not posted in the form but now they are posted as null values. I asked the Telerik team and they confirmed that this is expected behavior and they will be posting all the model back to controller.
What is bothering me is that a null value for a field is making Modelstate invalid even though the field is nullable and I'm not decorating it with Required attribute.
Here is my view model:
public class VMDoctorHospital
{
[HiddenInput(DisplayValue = false)]
public int DrHospitalID { get; set; }
[HiddenInput(DisplayValue = false)]
public int DoctorID { get; set; }
[DisplayName("Personal Clinic?")]
public bool PersonalClinic { get; set; }
[DisplayName("Clinic Name")]
public string ClinicName { get; set; }
[DisplayName("Hospital"), UIHint("IntStrEditor")]
public int? HospitalID { get; set; }
[DisplayName("Doctor's Position")]
//ohter fields
}
in the Model PersonalClinic flag dictates which input (Clinic name or HospitalID) will be disabled and hidden.
Now, even if they are posting null value for HospitalID when personalClinin checkbox is checked, it perfectly makes sense and on controller side HospitalID should be accepting null value as it is nullable and not REQUIRED but in reality I receive "The value "null" is not valid for HospitalID" in ModelstateDictionary.
I have no idea what is making it behave in this way.
This was considered a bug and will be addressed with the upcoming release.
精彩评论