Here is my model
public class Vehicles { [Key] public int Id { get; set; } public string Make { get; set; } }
view file
<div class="col-md-6"><div class="form-group row"><label asp-for="Vehicles.Make" class="control-label col-3 col-form-label">Make</label><div class="col-9"><input class="form-control input-sm" type="text" id="TxtMake"
asp-for="Vehicles.Make" /><span asp-validation-for="Vehicles.Make" class="text-danger">@ViewBag.MakeValError</span></div></div></div><button type="submit" class="btn btn-primary form-control">Create</button>
controller
[HttpPost]
public async Task<IActionResult> UpsertVehicle(VehicleVM vehicleVM)
{
if (vehicleVM.Vehicles.Make.ToString() == "")
{
ViewBag.MakeValError = "Please give vehicle make"; // If the value is null , the message should be given in span validate control
}
else
{
_unitOfWork.VehicleRepo.Add(vehicleVM.Vehicles);
}
}