So I'm submitting an Ajax.ActionLink with HttpMethod = "POST" and it works great. However, as soon as I specify an AjaxOptions.OnSuccess callback it submits with "GET" and does a full post back because Request.IsMvcAjaxRequest() is no longer true. Is
this a bug or am I doing something wrong here? I'm using the latest Beta version.
Works:
<%= Ajax.ActionLink("delete", "Delete", "Kind", new { id = kind.ID},
new AjaxOptions {
HttpMethod = "POST",
Confirm = "Are you sure you want to delete this Kind? This will delete any associated inventory items as well."
}, new { @class = "delete" }) %>
Doesn't Work:
<%= Ajax.ActionLink("delete", "Delete", "Kind", new { id = kind.ID},
new AjaxOptions {
HttpMethod = "POST",
Confirm = "Are you sure you want to delete this Kind? This will delete any associated inventory items as well.",
OnSuccess = "KindIndex.itemDeleted"
}, new { @class = "delete" }) %>
I have a feeling that you are specifying something else on the OnSuccess callback. make sure you are putting a javascript function name that exist.
i have tried exactly same code as yours except the fact that i have declared javascirpt function and put that name at OnSuccess and it worked perfectly. Here goes my code:
<script type="text/javascript">
function myCallback() {
alert('hello i got a call!');
}
</script>
<div id="divLoading">Loading ...</div>
<div id="divResultText"></div>
<%=Ajax.ActionLink("delete", "Delete", new { id = 20 }, new AjaxOptions { Confirm="Are you cure?", HttpMethod="POST", UpdateTargetId="divResultText", LoadingElementId="divLoading", OnSuccess = "myCallback" })%>
Please dont forget to click "Mark as Answer" on the reply that helped to solve your problem.
Marked as answer by ricka6 on Feb 17, 2009 11:12 PM
Thanks, that must have been it...I guess I was passing in something that wasn't in scope for the page. I'm kinda new to ASP.NET MVC so I think I had a script file that wasn't being loaded properly because the URL wasn't relative anymore. So Url.Content()
to the rescue. Thanks for your help.
grubbs.jc
0 Points
5 Posts
Ajax.ActionLink with AjaxOptions.OnSuccess uses GET even if POST is specified?
Nov 22, 2008 07:40 PM|LINK
So I'm submitting an Ajax.ActionLink with HttpMethod = "POST" and it works great. However, as soon as I specify an AjaxOptions.OnSuccess callback it submits with "GET" and does a full post back because Request.IsMvcAjaxRequest() is no longer true. Is this a bug or am I doing something wrong here? I'm using the latest Beta version.
Works:
<%= Ajax.ActionLink("delete", "Delete", "Kind", new { id = kind.ID},
new AjaxOptions {
HttpMethod = "POST",
Confirm = "Are you sure you want to delete this Kind? This will delete any associated inventory items as well."
}, new { @class = "delete" }) %>
Doesn't Work:
<%= Ajax.ActionLink("delete", "Delete", "Kind", new { id = kind.ID},
new AjaxOptions {
HttpMethod = "POST",
Confirm = "Are you sure you want to delete this Kind? This will delete any associated inventory items as well.",
OnSuccess = "KindIndex.itemDeleted"
}, new { @class = "delete" }) %>
ASP.NET mvc
JC
hassan.live
Member
132 Points
51 Posts
Re: Ajax.ActionLink with AjaxOptions.OnSuccess uses GET even if POST is specified?
Nov 23, 2008 07:49 PM|LINK
Hey
I have a feeling that you are specifying something else on the OnSuccess callback. make sure you are putting a javascript function name that exist.
i have tried exactly same code as yours except the fact that i have declared javascirpt function and put that name at OnSuccess and it worked perfectly. Here goes my code:
<script type="text/javascript"> function myCallback() { alert('hello i got a call!'); } </script> <div id="divLoading">Loading ...</div> <div id="divResultText"></div>grubbs.jc
0 Points
5 Posts
Re: Ajax.ActionLink with AjaxOptions.OnSuccess uses GET even if POST is specified?
Nov 23, 2008 08:16 PM|LINK
Thanks, that must have been it...I guess I was passing in something that wasn't in scope for the page. I'm kinda new to ASP.NET MVC so I think I had a script file that wasn't being loaded properly because the URL wasn't relative anymore. So Url.Content() to the rescue. Thanks for your help.
JC
hassan.live
Member
132 Points
51 Posts
Re: Ajax.ActionLink with AjaxOptions.OnSuccess uses GET even if POST is specified?
Nov 24, 2008 05:49 PM|LINK
Hi,
dont forget to set the topic as resolved and mark the correct answer if its solve your problem.
Thanks a lot.
maxstell
Member
4 Points
2 Posts
Re: Ajax.ActionLink with AjaxOptions.OnSuccess uses GET even if POST is specified?
Apr 07, 2010 01:02 AM|LINK
Hi everybody, i'm having the same problem
<%= Ajax.ActionLink("teste", "Create", new AjaxOptions { HttpMethod = "POST" })%>
When i click on this Link it call the "GET" Create Method from controller. Why ?
Thanks