问题描述
尊敬的专家,
在mvc3-i中,我希望某些东西在后台执行,并且其回调再次返回到同一页面,得到2件事-"Exception"& 成功".为此,我正在使用Ajax()-
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"); }
});
此动作方法工作正常. TableModel有2个属性Error(类型异常)和IsSuccessfull(布尔),这些是我实际上想要的属性.因此,在ajax()的error function()中,我可以获得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);
}
推荐答案
此动作方法工作正常. TableModel有2个属性Error(类型异常)和IsSuccessfull(布尔),这些是我实际上想要的属性.因此,在ajax()的error function()中,我可以获得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);
}
这篇关于如何使用jquery ajax()回调后获取一些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!