I have a unique Action method that handles exceptions by returning an _error
partial view:
[AcceptVerbs(HttpVerbs.Post)]
public PartialViewResult Register(string id, int classid) {
try
{
Thread.Sleep(3000);
User user = r.FindUser(id);
Users_Classes uc = new Users_Classes();
uc.AddedDate = DateTime.Now;
uc.ClassID = classid;
user.Users_Classes.Add(uc);
r.Save();
ViewBag.classid = classid;
return PartialView("_usersearch2", uc);
}
catch (DataException ex)
{
return PartialView("_error");
}
Here is the content of the _error
partial view:
<script type="text/javascript">
alert('The user might have been already Assinged, Search Again to get the latest users');
</script>
The current approach works well, but some may argue it is not a good design to display only an alert in a partial view. Are there better alternatives to achieve this functionality?