I call this action using jquery
public ActionResult Delete(int Id){
Schedule schedule = context.Schedules.FirstOrDefault(s => s.Id == Id);
try{
context.Schedules.Remove(schedule);
context.SaveChanges();
TempData["Message"] = "Succesfully removed schedule.";
return Content(Boolean.TrueString);
}catch(Exception ex){
TempData["Message"] = "Something went wrong";
return Content(Boolean.FalseString);
}
}
On my view I have a div that handles the TempData[“Message”] from the master
<div id="messages">
<% if(ViewContext.TempData["Message"] != null { %>
<div class="alert">
<%: ViewContext.TempData["Message"] %>
</div>
<% } %>
</div>
this is exactly how my jquery looks like. using the Boolean.TrueString / FalseString return. I’m not really sure if that’s the right way, as I’m still starting to learn jquery with actions.
http://ricardocovo.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/
Basically my goal is to be able to show any errors, or notify the users of anything that is wrong or any instructions that needs to be done to finish the steps. Was thinking of maybe just using JSON as the return type? I’m not really sure how to handle it.
any recommendations is very much appreciated.
you are using an ajax call; the View won’t get fully rendered again; to be able to show a message you’ll have to return it as json for example and handle it in the jquery callback.