Ticket Q575383
Visible to All Users

FormLayout - How to show model's ErrorMessage

created 11 years ago

I have an MVC grid which calls an external FormLayout
I have some Annotations on the Model with the Required Tag
These are showing fine on the Form with a marker beside the field (i,e. they show a --> *)
Also, I am not allowed Save unless these are filled in

However, whats not happening is the the Error Message is not being displayed when I try to Save

How do I get the ErrorMessage to show to the Right of the field (In red) if there is an error on the field

C#
namespace Club.Models { [MetadataType(typeof(MemberMD))] public partial class Member { } public class MemberMD { [Required(ErrorMessage= "First Name is required")] [Display(Name = "First Name")] public string FirstName { get; set; } [Required(ErrorMessage= "Surname is required")] [Display(Name = "Sur Name")] public string SurName { get; set; } [Display(Name = "Mobile")] public string TelMobile { get; set; } [Display(Name = "Home Tel")] public string TelHome { get; set; } } }
HTML
@model Club.Models.Member @{ Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript(); } @using(Html.BeginForm("ExternalEditFormEdit","Member",FormMethod.Post, new { @class = "edit_form"})) { @Html.DevExpress().FormLayout(settings => { settings.Name = "Member Details"; var mainDetails = settings.Items.AddGroupItem("Main Details"); mainDetails.Items.Add(i => i.MemberId); mainDetails.Items.Add(i => i.Salutation); mainDetails.Items.Add(i => i.FirstName); mainDetails.Items.Add(i => i.SurName); mainDetails.Items.Add(i => i.Gender); mainDetails.Items.Add(i => i.TelMobile); mainDetails.Items.Add(i => i.TelHome); mainDetails.Items.Add(i => i.Email); mainDetails.Items.Add(i => i.DateOfBirth); var memberDetails = settings.Items.AddGroupItem("Membership Details"); memberDetails.Items.Add(i => i.DateJoined); memberDetails.Items.Add(i => i.CurrentSubType); memberDetails.Items.Add(i => i.RenewalDate); var adrDetails = settings.Items.AddGroupItem("Address Details"); adrDetails.Items.Add(i => i.Ad1); adrDetails.Items.Add(i => i.Ad2); adrDetails.Items.Add(i => i.Ad3); adrDetails.Items.Add(i => i.Town); adrDetails.Items.Add(i => i.County); adrDetails.Items.Add(i => i.Country); }).GetHtml() @Html.DevExpress().Button( settings => { settings.Name = "btnUpdate"; settings.ControlStyle.CssClass = "button"; settings.Text = "Update"; settings.UseSubmitBehavior = true; }).GetHtml() @Html.DevExpress().Button( settings => { settings.Name = "btnCancel"; settings.ControlStyle.CssClass = "button"; settings.Text = "Cancel"; settings.ClientSideEvents.Click = "function(s, e){ document.location='" + DevExpressHelper.GetUrl(new { Controller = "Member", Action = "MembersMaintain" }) + "'; }"; }).GetHtml() }

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hi Gerard,
To accomplish your task it is necessary to enable the ShowModelErrors property of the layout item's editor extension. For example use the following code for this purpose:

C#
Html.DevExpress().FormLayout(settings => { settings.Name = "Member Details"; var mainDetails = settings.Items.AddGroupItem("Customized Fields"); ... mainDetails.Items.Add(i => i.FirstName, item => { (item.NestedExtensionSettings as TextBoxSettings).ShowModelErrors = true; }); ... }).GetHtml()

Please refer to the Model Validation help topic for more information.

    Comments (2)

      Hi Vasily. Thnaks for your reply
      Yes, I will try this, but it means having to put this into each control
      Is there not a higher level setting that I can use, that will apply to the whle project, or Model, so that I don not have to enter this into each control in the view

      DevExpress Support Team 11 years ago

        Hi,
        I recommend that you refer to the following article for a possible solution:
        Displaying Validation Error Messages

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.