I have face a problem in Model Validation .It's me model code
public class EducationalImageViewModel
{
[Required(ErrorMessage = "Please enter ImageTitle")]
public string Title { get; set; }
//public string Video { get; set; }
[Required(ErrorMessage = "File Shouldn't Be Empty Please select file")]
public string Image { get; set; }
public int EducationalId { get; set; }
[Required(ErrorMessage = "Please enter ImageDescription")]
public string Description { get; set; }
}
public class EducationalImageList
{
public List lst_EducationImageData { get; set; }
[Required(ErrorMessage = "Please enter ImageTitle")]
public string Title { get; set; }
//public string Video { get; set; }
[Required(ErrorMessage = "File Shouldn't Be Empty Please select file")]
public string Image { get; set; }
public int EducationalId { get; set; }
[Required(ErrorMessage = "Please enter ImageDescription")]
public string Description { get; set; }
}
This is my view code
@using (Html.BeginForm("EducationalI", "EducationalManagement", FormMethod.Post, new { id = "CreateForm", enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
Add New Image
 
@*@Html.TextBoxFor(x => x.Image, new { @type = "text", @id = "img", @class = "form-control" })*@
@Html.ValidationMessageFor(x => x.Image, "", new { @class = "text-danger" })
@Html.TextBoxFor(x => x.Title, new { @type = "text", @id = "ImageName", @class = "form-control", @placeholder = "Enter Title" })
@**@
@Html.ValidationMessageFor(x => x.Title, "", new { @class = "text-danger" })
@Html.TextBoxFor(x => x.Description, new { @type = "text", @id = "DescriptionName", @class = "form-control", @placeholder = "Enter Description", })
@**@
@Html.ValidationMessageFor(x => x.Description, "", new { @class = "text-danger" })
}
Validation message are not show after click button.
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Sep 16, 2020, 3:45 AM
Sachin SinghPosted Sep 15, 2020, 1:11 PM
• ModelState is of Type ModelStateDictionary which holds the collection of name and value pairs that were submitted to the server during a POST.
• It contains a collection of error messages for each value submitted.