title: How to pass error message to mvc view in ajax call
body: <p>I'm using ajax to call controller action method on mvc button click event. Controller action method  has validation logic which if failed user should be notified an error. I'm not sure how i can achieve this in MVC . Is there a way I can send error message to the ajax success event from controller?.</p>
  
  <pre><code> Controller Action Method
      [AcceptVerbs(HttpVerbs.Post)]
      public ViewResult Index(ProfileSnapshotRequestModel pspm)
      {
  
          // Do something 
         return Json(new { success = true });
      }
  </code></pre>
  
  <p>MVC view button click</p>
  
  <pre><code>   $("#copyData").click(function() {
  
              var selectedRowId = $('#ServersWS').jqGrid('getGridParam', 'selrow');
              var rowData = jQuery("#ServersWS").jqGrid('getRowData', selectedRowId);
              $("#MainDiv").prop('disabled', true);
              var url = '@Url.Action("Index")';
              HideElements();
              $.ajax({
                  url: url,
                  data: {
                              BaseEnvtId: $("#SelectedEnvironmentID").val(),
                              BaseVersionId: $("#SelectedVersionID").val(),
                              BaseProfileId: rowData['ProfileId'],
                              NewEnvtId: $("#SelectedEnvironmentID2").val(),
                              NewVersionId: $("#SelectedVersionID2").val(),
                              NewProfileId: $("#SelectedProfileID2").val(),
                  },
                  type: 'POST',
                  datatype: 'json',
                  success: function(data) {
                      document.getElementById('displaySuccess').style.display = 'block';
                      $("#ProfileCopyDiv").prop('disabled', true);
                      $("#MainDiv").prop('disabled', false);
                  },
                  error: function() { alert('something bad happened'); }
              });
          });
  </code></pre>