我有一個JavaScript函數重定向到Asp.net MVC操作方法。jquery .ajax在asp.net中的POST函數錯誤返回MVC
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SupplierDetail(int SupplierID)
{
int test = SupplierID;
return View();
}
/// Java Script Code ...
$('#list .clsRowButtonClick').live('click', function() {
var id = $(this).attr('RowID');
var type = $(this).attr('ButtonType');
alert("ID: " + id + " \nButtonType :" + type);
var Supplier = {};
Supplier.SupplierID = id;
var jsonString = JSON.stringify(Supplier);
$.ajax({
type: "POST",
url: "/Supplier/SupplierDetail/",
dataType: "json",
data: jsonString,
contentType: "application/json; charset=utf-8",
success: function (response, textStatus, jqXHR) {
alert("success");
},
error: function (jqXHR, textStatus, errorThrown) {
//alert(jsonString);
alert("jqXHR.responseText --> "+ jqXHR.responseText + "\njqXHR --> " + jqXHR + "\ntextStatus --> " + textStatus + " \nerrorThrown --> " + errorThrown);
}
});
});
它按我的預期工作。它通過提供校正的參數值激發SupplierDetail
Action Method。
但是,在調用名爲SupplierDetail
的動作方法後引發錯誤的是什麼問題。
所以我使用javascript alert function
來追溯代碼。
jqXHR.responseText --> <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>SupplierDetail</title>
<link href="/Content/themes/Redtheme/theme.css" rel="stylesheet" type="text/css" />
<link href="/Content/themes/Redtheme/style.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.6.3.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<script src="/Scripts/modernizr-2.0.6-development-only.js" type="text/javascript"> </script>
<link href="/Scripts/jqgrid_utils/css/cupertino/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" />
<link href="/Scripts/jqgrid_utils/css/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jqgrid_utils/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.base.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.celledit.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.common.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.custom.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.filter.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.formedit.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.grouping.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.import.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.inlinedit.js" type="text/javascript"> </script>
<script src="/Scripts/jqgrid_utils/grid.jqueryui.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.loader.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.subgrid.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.tbltogrid.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/grid.treegrid.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/jqDnR.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/jqModal.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/jquery.fmatter.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/JsonXml.js" type="text/javascript"></script>
<script src="/Scripts/jqgrid_utils/jquery.jqGrid.min.js" type="text/javascript"> </script>
</head>
<body>
<div id="container">
<div id="header">
<div>
<h2>POS 2012</h2>
</div>
<div id="topmenu">
<ul>
<li class="current"><a href="./MemberRegistration.jsp">Suppliers</a></li>
<li><a href="./RetailerRegistration.jsp">Products</a></li>
<li><a href="./Index.jsp">SupplierOrder</a></li>
<li><a href="#">Contact us</a></li>
</ul>
</div>
</div>
<div id="wrapper">
<h2>SupplierDetail</h2>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"> </script>
<form action="/Supplier/SupplierDetail/" method="post"> <fieldset>
<legend>Supplier</legend>
<div class="editor-label">
<label for="SupplierName">SupplierName</label>
</div>
<div class="editor-field">
<input class="text-box single-line" id="SupplierName" name="SupplierName" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="SupplierName" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Address">Address</label>
</div>
<div class="editor-field">
<input class="text-box single-line" id="Address" name="Address" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Address" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Phone">Phone</label>
</div>
<div class="editor-field">
<input class="text-box single-line" id="Phone" name="Phone" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Phone" data-valmsg-replace="true"></span>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
</form>
<div>
<a href="/">Back to List</a>
</div>
</div>
<div id="footer">
<div id="credits">
Copy right © ....
</div>
<br />
</div>
</div>
</body>
</html>
jqXHR --> [object Object]
textStatus --> parsererror
errorThrown --> SyntaxError: JSON.parse: unexpected character
每個建議將不勝感激。