@model IEnumerable<HitecPoint.BlackBox.Models.SMSReportModal>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script>
<script type="text/javascript">
var MyAppUrlSettings =
{
DistanceReportURL: '@Url.Action("SmsReport", "SmsReport")',
}
</script>
<script type="text/javascript" >
$(document).ready(function () {
alert('hi');
//Initialize Page
initializePage();
//Distance link click
$("#SearchS_R").click(function () { getDistanceReport(); });
});
function initializePage() {
$("#SmsReport").html('');
}
</script>
<script type="text/javascript">
function getDistanceReport() {
var obj = {};
obj.BBID = "D527";
obj.Interval = 0;
$.ajax({
type: "POST",
url: MyAppUrlSettings.DistanceReportURL,
data: "{obj:" + JSON.stringify(obj) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data.Html) {
$("#SmsReport").html(data.Html);
}
else {
$("#SmsReport").html("<p style='color: #AFAEAE; font-family: status-bar; font-size: 16px; font-weight: bold; margin: 30%;'> No Data available </p>");
}
$("#overlay").fadeOut();
$("#loading").hide();
},
error: function (request, status, error) {
alert(error);
$("#overlay").fadeOut();
$("#loading").hide();
}
});
}
我的功能如下。我创建了一个SMSReportModal
类,其中我声明了对象的所有属性
public ActionResult SmsReport(SMSReportModal _SMRobj)
{
string k = _SMRobj.BBID;
return Json(true);
}
我在razor
中使用Mvc
。我想使用ajax将数据对象传递给函数,但函数返回object的null值。我做错了。请帮忙
答案 0 :(得分:1)
试试这个
...
data: {_SMRobj:JSON.stringify(obj)},
...