There is a lot going on here.
I have a Telerik MVC grid with the following templated column:
@(Html.Telerik().Grid((IEnumerable<User)Model.Data)
.Name("UsersGrid")
.DataKeys(keys => keys.Add(c => c.UserName))
.DataBinding(dataBinding => dataBinding.Server()
.Columns(c =>
{
c.Bound(r => r.FullName).Title("");
c.Bound(r => r.UserName).Title("");
c.Template(
@<text>
@if(@item.Status == "Pending")
{
@Html.ActionLink("Resend Invite", "ResendInvite", new { Email = @item.UserName, FirstName = @item.FullName }, new { @class = "reesendInviteLink" })
}
</text>
).Title("Link").HtmlAttributes(new { Style = "text-align: right;" });
}));
Now I know ActionLink will not call a post action so I’m doing the following with jquery:
$(document).ready(function () {
$(".resendInviteLink").click(function (e) {
var url = e.currentTarget.href;
$.post(url);
});
});
The Action method I am trying to call looks like this:
[HttpPost]
public ActionResult ResendInvite(UserVM user)
{
//....Do Something
}
When I debug the jquery everything goes well until I reach the $.post and then it fails saying that it cannot find the ResendInvite action on the controller. In a way I think it makes sense since the ActionLink is looking for a Get, not a Post.
So how can I create a link on the grid that will:
1. Get the email and the user’s name from the Telerik grid.
2. Call a post action method with the correct paameters.
Thanks for your help.
Your problem is that although you’ve subsribed on the link’s
click eventwith Jquery, the link’s originalclick eventstill fires a Get request which fails.You need to use the preventDefault method
Or
return falseform the event handler: