Mam problem formularz nie przechodzi walidacji wydaje mi się że jest to przez relacje
//Relations
public List<BooksReviews> BooksReviews { get; set; }
lecz nie wiem dlaczego ona jest sprawdzana jak nie jest użyta w Bind. To jest summary z ModelValidation podczas próby przesłania formularza
Nadole dane wysyłane przez formularz
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group text-center">
<img id="ProfilePicturePreview" class="border-info rounded-circle" style="max-width: 150px" />
</div>
<div class="form-group">
<label asp-for="ProfilePicture" class="control-label"></label>
<input asp-for="ProfilePicture" class="form-control" />
<span asp-validation-for="ProfilePicture" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="FullName" class="control-label"></label>
<input asp-for="FullName" class="form-control" />
<span asp-validation-for="FullName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Note" class="control-label"></label>
<input asp-for="Note" class="form-control" />
<span asp-validation-for="Note" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-outline-success float-right" />
<a class="btn btn-outline-secondary" asp-action="Index">Show All</a>
</div>
</form>
Contllorer Create który bez walidacji działa poprawnie
[HttpPost]
public async Task<IActionResult> Create([Bind("ProfilePicture,FullName,Note")] Reviewer reviewer)
{
if (ModelState.IsValid)
{
await _service.AddAsync(reviewer);
return RedirectToAction(nameof(Index));
}
else {
return View(reviewer);
}
}
Sam Model
public class Reviewer
{
[Key]
public int Id { get; set; }
[Display(Name = "Profile Picture")]
[Required(ErrorMessage = "Profile Picture is required")]
public string ProfilePicture { get; set; }
[Required(ErrorMessage = "Full Name is required")]
[MaxLength(50)]
[MinLength(5)]
public string FullName { get; set; }
[Display(Name = "Note")]
[Required(ErrorMessage = "Note is required")]
public string Note { get; set; }
//Relations
public List<BooksReviews> BooksReviews { get; set; }
}
[Bind(Include == example)] nie działa
Moje pytanie to jak nakierować formularz by wysyłał tylko te dany które wymagam/chce