- Home
- Forum
- ASP.NET MVC - EJ 2
- Data Annotation in Grid
Data Annotation in Grid
Hi Sujith,
thank you for your support.
I can't figure out where the problem is, because the code in the sample is almost identical to mine, but field validation doesn't work for me.
I think I understand the problem, to use validation I add a Metadata class to the class generated by entity framework, this works for page markup, but not for Syncfusion components. I tried to create a view-model class with data-annotations and by switching this type to the grid, required validation worked, but it displayed a different message to what I had imposed on the Required attribute.
[MetadataType(typeof(ImpostazioneMetadata))]
public partial class Impostazione
{
}
public class ImpostazioneMetadata
{
[Key]
public Guid IdImpostazione { get; set; }
[Display(Name = "Nome", ResourceType = typeof(Resources.Impostazioni))]
public string Nome { get; set; }
[Display(Name = "Valore", ResourceType = typeof(Resources.Impostazioni))]
[Required(ErrorMessageResourceType = typeof(Resources.Impostazioni), ErrorMessageResourceName = "ValoreObbligatorio")]
public string Valore { get; set; }
}
In all this, you can solve the problem, without using a view-model, and why is the error message different from that of the attribute?
|
[Required(ErrorMessageResourceName = "ValidationErrorRequiredField")]
public string CustomerID { get; set; } |
- Let us know if you are able to reproduce/replicate your problem scenario in the above provided sample. It would be helpful to identify your exact problem case and provide the solution based on that.
- Have you set validation rules in the Grid columns? If so, it might be causing to display the default validation message set in the Grid. Try removing that validation and ensure if the proper message is displayed.
- Let us know the current validation message displayed and the error message that you need to be displayed.
- Syncfusion package version used.
- Share us the Grid code file to ensure with your Grid settings.
Hi Sujith,
Thank you for your support.
I will check whether the proposed amendment works.
But, it's not clear to me if I can use a metadatatype class to "tie" data annotations or I'm forced to use a view-model.
Hi Sujith,
Thank you for your support.
But I can't translate the error message, as predicted by the model.
This is my Data-annotation:
[Display(Name = "Valore", ResourceType = typeof(Resources.Impostazioni))][Required(ErrorMessageResourceType = typeof(Resources.Impostazioni), ErrorMessageResourceName = "ValoreObbligatorio")] public string Valore { get; set; }
This shows the following message: "Il campo "Valore" è obbligatorio"
But in the template dialog it appears as follows:
To confirm what was indicated in the previous message, in another view-model class I entered the EmailAddress attribute, but in the grid dialog, there is no error message if you enter an incorrect email address, for example without @.
It seems that data-annotations are not read or not in the correct way.
|
[Required(ErrorMessage = "Il campo Valore è obbligatorio")]
public string CustomerID { get; set; } |
|
[EmailAddress]
public string Email { get; set; } |
Hi Sujith,
I modified the example you sent, adding a resource and a view-model, and the error message continues to be the standard one and not the expected one.
For the email issue, this is the portion of code used in the grid editing template:
<div class="col-sm-6 mb-3 mb-sm-0">
@Html.LabelFor(m => m.Email, new { @class = "text-xs font-weight-bold text-uppercase mb-1" })
@Html.EditorFor(m => m.Email, new { htmlattributes = new { @class = "form-control-grid" } })
@Html.ValidationMessageFor(m => m.Email, "", new { @class = "small text-danger" })
</div>
Attachment: GridUpdated1568965575_772b2c48.zip
|
[Required(ErrorMessage = "Il campo Valore è obbligatorio")]
public string CustomerID { get; set; } |
Hi Sujith,
So can't I use resx to translate messages?
- 13 Replies
- 2 Participants
-
PL Pio Luca Valvona
- Jun 20, 2021 10:29 AM UTC
- Jul 5, 2021 12:47 PM UTC