I want to validate user input using the [Remote] attribute. This is how this code looks in the model:
[Remote(action:"VertifyPeriod",controller:"AllTasks")]
public string Period { get; set; }
This is what the controller code looks like:
[AcceptVerbs("GET", "POST")]
public IActionResult VertifyPeriod(AllTask allTask)
{
if (!string.IsNullOrEmpty(allTask.Period))
{
return Json(true);
}
return Json($"Wrong period value!");
}
View code:
<form asp-antiforgery="true" asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Period" class="control-label"></label>
<input type="text" asp-for="Period" class="form-control" />
<span asp-validation-for="Period" class="text-danger"></span>
</div>
If the user leaves the string empty the condition returns true, although it should return false It is listed as null in the database. I noticed peculiarity: If set a breakpoint on a conditional statement, it will never be reached. If I make another check condition, not related to checking for null then everything works fine. IsNullOrWhiteSpace doesn't work either. What could be the problem?