I’ve got some jquery that’ll run ajax that runs a controller action that returns a partial view. In some cases i want to display one of several error messages (controlled by the controller), rather than replacing a DOM element with the result.
How do I achieve this?
Currently I have this:
$.ajax({
type: "POST",
cache: false,
url: '<%= Url.Action("AddPostcodeToTerritory", "Territories") %>'
}).done(function(data) {
$("#SelectedTerritoryPostcodeRows").html(data);
});
I have the element SelectedTerritoryPostcodeRows which normally gets the information, but I also want the controller to be able to give some error message which I want to display somewhere else.
Your not returning any errors, so you need some identifier in your response so your script knows what to do. Perhaps another element called errMsg, and a new if..then to handle it in this script will sort it.