0

我的表单中有 ajax.actionlink:

<% using (Html.BeginForm("UpdateRecordingDetails", "Recording", FormMethod.Post, new { id = "frmRecordingEdit" }))
   {%>
       <%= Ajax.ActionLink("Event Notifications", "procesCallrecording", new { Id = ViewData["RecordingIDsEdit"] }, new AjaxOptions { OnSuccess = "alert('success message');" })%>
    <%            
   } 
%>

控制器动作是这样的:

public JsonResult procesCallrecording(int Id = 0 ) 
{
    return Json("success", JsonRequestBehavior.AllowGet);
}
4

3 回答 3

0

If this is an ASP.NET MVC 2 application make sure that you have included the MicrosoftAjax.js and MicrosoftMvcAjax.js scripts to your page:

<script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftAjax.js") %>"></script>
<script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftMvcAjax.js") %>"></script>

In ASP.NET MVC 3 or later those are obsolete and should no longer be used. They are replaced by the jquery.unobtrusive-ajax.js script.

于 2013-03-16T17:46:59.810 回答
0

我认为OnSuccessAjax.ActionLink 的回调需要javascript在事件发生时调用一个函数名。

      <%= Ajax.ActionLink("Event Notifications", "procesCallrecording", new { Id = ViewData["RecordingIDsEdit"] }, new AjaxOptions { OnSuccess = "success" })%>

正如您所期望的那样,javascript 是一个警报。

   <script>
  function success(){
         alert('success message');
    }
   </script>

这种方式你可以试试

于 2013-03-16T17:45:03.617 回答
0
<%= Ajax.ActionLink("Event Notifications", "procesCallrecording", 
    new { Id = ViewData["RecordingIDsEdit"] }, 
    new AjaxOptions { 
        OnSuccess = "function() { alert('success message'); 
    }" })%>

还有更好的方法在这里检查

于 2013-03-16T10:27:04.403 回答