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; } |
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>
[Required(ErrorMessage = "Il campo Valore è obbligatorio")]
public string CustomerID { get; set; } |
Hi Sujith,
So can't I use resx to translate messages?