Show / Hide does not enable / disable sending the value to Controller.
Items or simply not editable will be returned (in 99% of cases) as / . DisablednullminVal
You can set the elements in the view as Disabledusing JQueryin the script:
$('#elementID').attr("disabled", true);
OR you can use the command DOM:
document.getElementById('elementID').disabled = "true";
Thus, you can set the fields as DisabledANDHidden , so that it is not displayed or populated . Then in Controlleryou can simply base your business logic on whether or not certain fields (preferred mandatory fields, if any) are null.
C# :
string:
if (string.IsNullOrWhiteSpace(Model.stringField))
{
ModelState.AddModelError("stringField", "This is an error.");
}
DateTime:
if (Model.dateTimeField == DateTime.MinValue)
{
ModelState.AddModelError("dateTimeField ", "This is an error.");
}
, / JQuery:
$('#elementID').hide();
$('#elementID').show();