Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3
Dear Experts,
 
In mvc3-i want some stuff to be perform in background and its callback comes again to the same page getting 2 things-"Exception" & "IsSuccessfull". For that i am using Ajax()-
$.ajax({
                        url: '//localhost:1787/Table/Index/',
                        type: "POST",
                        data: JSON.stringify(tb),
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        async:true,
                        success: function (data) {
                            $('.result').html(data);
                            alert('success');
                        },
                        error: function () { alert("error"); }
                    });
 
This action method working fine. TableModel have 2 property Error(of type exception) and IsSuccessfull(bool),these are the properties which i actually want..so that in error function() of ajax() i can get the Error property. how to go,don't know??
 
public ActionResult Index(TableModel tb)
        {
            string tablename = tb.TableName;
            TableModel tableModel = new TableModel();
            try
            {
               ....doning some stuff, getting the result in "var result".
               if (!result.IsOperationSuccessful)
               {
                   tableModel.Error=result.Error;
               }
            }
            catch (ArgumentNullException ex)
            {
                tableModel.Error = ex;
            }
            catch (ArgumentException ex)
            {
                tableModel.Error = ex;
            }
            return View(tableModel);
        }
Posted 14-May-12 21:34pm
Edited 14-May-12 22:16pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can try like this
 
$.ajax({
url: '//localhost:1787/Table/Index/',
type: "POST",
data: JSON.stringify(tb),
dataType: "json",
contentType: "application/json; charset=utf-8",
async:true,
success: function (data) {
$('.result').html(data.Error);
alert(data.Error);
alert(data.IsSuccessfull);
alert('success');
},
error: function () { alert("error"); }
});
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100