I am using the following code to achieve sorting:
<button type="button" class="btn btn-default @(Model.SortOrder.Trim().ToUpper().Equals("NAME") ? "active" : "")">
@Ajax.ActionLink("Name", "Cause", "Search", new { query = Model.Query, category = Model.Category, pageNumber = 0, sortOrder = "NAME", sortDirection = "ASCENDING" }, new AjaxOptions() { UpdateTargetId = "SearchCauseSelfWidgetContent", InsertionMode = InsertionMode.Replace, OnSuccess = "PostAjaxLoad()" })
</button>
As you might expect, when I click on the text inside the button it works, but if I click anywhere else (the padding between button boundary and text) it does not do anything.
Since there does not seem to be a Url.
helper for ajax methods, and there is no Ajax.ButtonLink
, I am a little bit lost on how to wrap the whole button in this ajax call.
I was being thick. In this case (with Bootstrap classes) I just needed to add the button's class
es, "btn btn-default"
to my ActionLink
's @class
:
@Ajax.ActionLink(
"Name",
"Cause",
"Search",
new { query = Model.Query, category = Model.Category, pageNumber = 0, sortOrder = "NAME", sortDirection = "ASCENDING" },
new AjaxOptions() { UpdateTargetId = "SearchCauseSelfWidgetContent", InsertionMode = InsertionMode.Replace, OnSuccess = "PostAjaxLoad()"},
new { @class = "btn btn-default" } // < -- added.
)
pull the ajax call out and tie it to the button click
$('.btn-default').on('click', function () {
$.ajax({
type: 'POST',
url: '@Url.Action("Action", "Controller")',
data: {
query: '@Model.Query',
category: '@Model.Category',
etc...
},
cache: false,
async: true,
success: function (data) {
$('#SearchCauseSelfWidgetContent').html(data);
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With