我在 mvc 中将事件更改为文本框一切正常,但我无法处理控制器在视图中抛出的异常。
**VIEW:**
$("#txtToloc").change( function (event) {
var toloc= $('#txtToloc').val();
var mn = <%= new JavaScriptSerializer().Serialize(ViewData["MODELNUMBER"])%>;
var fm = <%= new JavaScriptSerializer().Serialize(ViewData["lblocation"]) %>;
var it = <%= new JavaScriptSerializer().Serialize(ViewData["lbinvtype"])%>;
var whid = "14";
debugger;
$.ajax({
url: '<%: Url.Action("GetPartialGraph")%>',
data: { 'Tolocation' :mn, 'Frmlocation' :fm, 'moNo' :it, 'whid' : whid },
type: "post",
cache: false,
dataType: "html",
success: function(result) {
alert('yeap');
},
error: function(xhr, status, error) {
alert(‘loss’);
}
});
});
});
从视图中我在控制器中调用动作方法。
**CONTROLLER.**
public ActionResult GetPartialGraph(string Tolocation, string Frmlocation, string moNo, string whid)
{
string isvalid = "0";
if (Frmlocation.ToUpper().Trim() == Tolocation.ToUpper().Trim())
{
}
else
{
try
{
ut.Setlocation(Tolocation,Frmlocation,moNo,whid);
}
catch (iDB2Exception ex)
{
/* in catch depending upon certain condition I want through diff exception */
return View(isvalid);
}
Everything works fine. But I am unable to bring exception back to view. To show proper message to client. From
error: function(xhr, status, error) {
alert(‘loss’);
}
我将调用另一个函数,并根据返回值向用户显示消息。我无法从控制器返回异常以显示在视图中。