0

I am working on asp.net mvc application and I have added an actionlink like this:

<%= Ajax.ActionLink("Event Notifications", "processCallrecording", new { Id = ViewData["RecordingIDsEdit"] }, new AjaxOptions
{
    OnSuccess = "StatusChanged",
    HttpMethod = "POST"
})%>

My controller is like this:

 [HttpPost]
        public JsonResult ProcessCallRecording(int Id = 0)
        {
int result = id;
 return Json(new {NewStatus = result.ToString()});
        }

My js function is like this:

function StatusChanged(data) {   
alert("order #:" + data.NewStatus + "has a new status: "
    + data.NewStatus);
}

and I see undefined in alert. I am struggling for last 2 hours on this issue. Please suggest me what is wrong ?

4

1 回答 1

0

尝试这个

<%= Ajax.ActionLink("Event Notifications", "processCallrecording", new { Id = Convert.ToInt32(ViewData["RecordingIDsEdit"]) }, new AjaxOptions
{
    OnSuccess = "StatusChanged",
    HttpMethod = "POST"
})%>

因为你我使用了 viewData,所以你错过了将其转换为 Int。还要确保我在操作链接之前添加了这些脚本。

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
于 2013-03-22T11:38:19.677 回答