Я получаю сообщение об ошибке при добавлении с помощью Fluent Validation. / Когда я пытаюсь выполнить проверку с помощью Fluent Validation, я получаю сообщение об ошибке.
Хотя я отправляю модель, она переводит ее на проверку при первом открытии.
Описание ошибки: Имена типов проверки в ненавязчивом клиенте правила проверки должны быть уникальными. Следующий тип проверки встречался более одного раза: требуется
Изображение ошибки:
введите описание изображения здесь
Добавленные библиотеки: Fluent Validation / FluentValidation. Mvc5 / FluentValidation.ValidatorAttribute 8.6.1
MVCApplication:
private void ValidationConfiguration()
{
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider
{
AddImplicitRequiredValidator = false
});
FluentValidationModelValidatorProvider.Configure(provider =>
{
provider.AddImplicitRequiredValidator = false;
provider.ValidatorFactory = new ValidatorFactory();
});
}
Class
[Table("Category")]
[Validator(typeof(CategoryValidator))]
public partial class Category
Категория Validator
public class CategoryValidator:AbstractValidator<Category>
{
public CategoryValidator()
{
this.CascadeMode = CascadeMode.StopOnFirstFailure;
RuleFor(x => x.Name).NotNull().WithMessage("Boş Geçilemez");
RuleFor(x => x.Name).NotEmpty().WithMessage("Boş Geçilemez");
}
}
View
@using (Ajax.BeginForm("CategoryAddOperation", "Category", FormMethod.Post, new AjaxOptions()
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = "returnPostCategoryAdd(data)",
LoadingElementId = "loading-background",
},
new
{
@class = "CategoryAdd needs-validation",
@area = "Admin",
@id = "frmCategoryAdd",
@name = "frmCategoryAdd",
@enctype = "multipart/form-data",
@novalidate = "novalidate"
}))
{
@Html.AntiForgeryToken()
<div class="form-group">
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name, "", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "invalid-feedback error-validate" })
</div>
@*<div class="form-group">
@Html.LabelFor(model => model.Description)
@Html.TextAreaFor(model => model.Description, new { @class = "form-control", @spellcheck = "false" })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "invalid-feedback error-validate" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Image)
<div class="custom-file">
@Html.TextBoxFor(model => model.Images, "", new { @type = "file", @class = "custom-file-input" })
@Html.LabelFor(model => model.Image, "Resim Seçiniz", new { @class = "custom-file-label", @data_browse = "Seçiniz" })
@Html.ValidationMessageFor(model => model.Image, "", new { @class = "invalid-feedback error-validate" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Banner)
<div class="custom-file">
@Html.TextBoxFor(model => model.Banners, "", new { @type = "file", @class = "custom-file-input" })
@Html.LabelFor(model => model.Banner, "Afiş Seçiniz", new { @class = "custom-file-label", @data_browse = "Seçiniz" })
@Html.ValidationMessageFor(model => model.Banner, "", new { @class = "invalid-feedback error-validate" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Header1)
@Html.EditorFor(model => model.Header1, "", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Header1, "", new { @class = "invalid-feedback error-validate" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Header2)
@Html.EditorFor(model => model.Header2, "", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Header2, "", new { @class = "invalid-feedback error-validate" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.MainMenuId)
@Html.DropDownListFor(model => model.MainMenuId, TempData["Categories"] as List<SelectListItem>, new { @class = "custom-select" })
@Html.ValidationMessageFor(model => model.MainMenuId, "", new { @class = "invalid-feedback error-validate" })
</div>*@
}