This is a migrated thread and some comments may be shown as answers.

How to display errors

1 Answer 22 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marina
Top achievements
Rank 1
Marina asked on 21 Jun 2011, 08:04 AM
How can I output the logical error to the user, in case I use grid ajax mode. How to refresh div witch display error?  for example, set 
ViewData["Message"]="Set here something like: You cannot do this because Item have Child"; on server
and dislpay
@Html.Label(ViewData["Message"].ToString()) on client

 

1 Answer, 1 is accepted

Sort by
0
Igniter
Top achievements
Rank 1
answered on 12 Aug 2011, 07:09 AM
On the grid you can add different client events. And on each of this event you can add a handler, for example:
<script type="text/javascript">
 //Delete project
 function onDeleteClick(e) {
  if (confirm("Are you sure you wish to delete this project?")) {
   $.post('<%= Url.Action( "Delete", "Project" ) %>'+ '/' + e, function (data) {
    var grid = $('#ProjectsTable').data('tGrid');
    grid.ajaxRequest();
   }).error(function (error) { ShowError(error); });
 }
}
 
//Show error
function ShowError(error) {
 $("#yourErrorLabel").html(error);
}      
<script>

And of cause throw corresponding error on the conroller:
public ActionResult Delete(int id)       
{
 if(somethingwrong)
 {
   trow new Exception("You cannot do this.");
 }
 return Content("");
}





Tags
General Discussions
Asked by
Marina
Top achievements
Rank 1
Answers by
Igniter
Top achievements
Rank 1
Share this question
or