Installed EA for trying to have a parameter be required if there is nothing in the database, IE. this is the first time someone is creating something.
However, the RequiredIf never fires for client side validation, even though when the model gets into the partial view, the BindingExists bool is set to false and the Xml value is still null.
Model:
public class AddTestStepXmlParameterModel
{
public ParameterTypeEnum ParameterType { get; set; }
public string ParameterName { get; set; }
public string Description { get; set; }
[RequiredIf("BindingExists == false", ErrorMessage = "An XML File is required: Please Try again")]
[FileExtensions(Extensions = "xml", ErrorMessage = "Specify an XML file.")]
public HttpPostedFileBase XmlValue { get; set; }
public bool BindingExists { get; set; }
}
Global.asax:
protected void Application_Start()
{
ModelValidatorProviders.Providers.Remove(ModelValidatorProviders.Providers.FirstOrDefault(x => x is DataAnnotationsModelValidatorProvider));
ModelValidatorProviders.Providers.Add(new ExpressiveAnnotationsModelValidatorProvider());
}
Scripts in View:
<script src="~/Scripts/jquery-3.1.0.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/expressive.annotations.validate.js"></script>
Partial View Call:
@Html.Partial("AddParameters", Model.AddTestStepModel.AddTestStepParametersModel)
Partial View:
@Html.HiddenFor(m => m.AddTestStepXmlParameterModels[k].BindingExists, new {@Value = Model.AddTestStepXmlParameterModels[k].BindingExists})
@Html.TextBoxFor(m => m.AddTestStepXmlParameterModels[k].XmlValue, new {type = "file", @class = "btn btn-default btn-file", style = "color:transparent", onchange = "this.style.color = 'black'"})
@Html.ValidationMessageFor(m => m.AddTestStepXmlParameterModels[k].XmlValue)
When using just a normal "Required", the Xml Value client side fires off fine, however using the RequiredIf fails to do any validation. I've followed the isntallation steps with the Global.asax