MVCxTrackBar.ShowModelErrors Property
Gets or sets a value that specifies whether or not model error messages should be automatically displayed for the editor when its value validation fails.
Namespace: DevExpress.Web.Mvc
Assembly: DevExpress.Web.Mvc5.v24.1.dll
NuGet Package: DevExpress.Web.Mvc5
Declaration
Property Value
Type | Description |
---|---|
Boolean | true if model error messages are automatically displayed for an invalid editor; false if the automatic error visualization feature is not used. |
Remarks
DevExpress MVC editors have the ShowModelErrors property that (when enabled) allows model error messages to be automatically displayed for invalid editors when validation fails. This minimizes your coding, since you do not need to use the Html.ValidationMessageFor extension method to visualize errors.
If the ShowModelErrors property is enabled, you can control how errors are visualized for an editor by using options exposed via the EditProperties.ValidationSettings property, available as the editor settings’ Properties.ValidationSettings property. For instance, you can play with the following options: ValidationSettings.ErrorDisplayMode, ValidationSettings.ErrorFrameStyle, ValidationSettings.ErrorImage.
To learn more, see our online demo: Data Editors - Validation
Example
View (“ModelValidation”):
...
<%
<!-- Here goes editor-type specific extension method, such as Html.DevExpress().TextBox( -->
settings => {
settings.Name = "SomeData";
...
settings.ShowModelErrors = true;
settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
}
)
.Bind(Model.SomeData)
.Render();
Model:
public class ModelValidationData {
[Required(ErrorMessage = "SomeData is required")]
public string SomeData { get; set; }
...
}
Controller:
[HttpGet]
public ActionResult ModelValidation() {
return View("ModelValidation", new ModelValidationData());
}
[HttpPost]
public ActionResult ModelValidation([ModelBinder(typeof(DevExpressEditorsBinder))] ModelValidationData validationData) {
if(ModelState.IsValid)
return View("ModelValidation", "ModelValidationSuccess", validationData);
else
return View("ModelValidation", validationData);
}