I have a Delete action something along this lines – abridged for this question:
[HttpGet]
public ActionResult Delete(int id)
{
var skill = _applicantSkillService.ReadApplicantSkill(id);
try
{
_applicantSkillService.DeleteApplicantSkill(skill);
}
catch (Exception ex)
{
return View(model);
}
}
Now my main concern in setting an error message in the view without building the whole view model again. Is there any way I can do this?
My second concern I have just noticed is this action method requires a view return, and the view requires a non-null model. What ‘escape routes’ do I have here?
You can place your error message in ViewData or TempData object and print it on view
like
Alternatively you can make a property of error message on your model and assign it before returning view like