Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

how can i bring the error message given in controller into the view span asp-validation please help

$
0
0

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);
		}

}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>