2
votes

I have specified the Action method to use for the Async request with Url.Action, but unlike with specifying the ajax options for a form and storing them i.e

 AjaxOptions ajaxOpts = new AjaxOptions {
UpdateTargetId = "tabledata",
Url = Url.Action("AppointmentData")
};

And than just passing this "ajaxOpts" into the Ajax.BeginForm() I am unable to store the ajax options in a variable and than pass that into Ajax.ActionLink. Please see the syntax I am attempting below:

@Ajax.ActionLink(cat.CATNAME, ajaxOpts, new { CatID = cat.CATID, count = Model.Count },
AjaxOptions ajaxOpts = new AjaxOptions
{
    UpdateTargetId = "catlist-" + Model.Count,
    Url = Url.Action("GetCats")

})

Whilst something like the below without trying to use graceful degradation works fine of course, but with jscript turned off it just emits the partialview without the rest of the page:

@Ajax.ActionLink(cat.CATNAME, "GetCats", new { CatID = cat.CATID, count = Model.Count },
new AjaxOptions
{
    UpdateTargetId = "catlist-" + Model.Count,  
})

It's understandable that when you don't specify the URL for the form and instead just use AjaxOptions as a parameter and jscript is turned off the form will just by default post back to the Action that rendered the page. But is something similar possible for the ActionLink ?

2

2 Answers

1
votes

This is because you would need a different action and/or check for an AJAX post to your controller action method. When you have javascript turned on, you are requesting a partial view and telling the javascript what target (div or span or whatever) to update with that partial view. When javascript is turned off, it sounds like you are still only returning a partial view, not a complete view. Since the javascript is turned off, you are not updating a div - just rendering the partial by itself.

In short, when it is not an AJAX request (JS turned off) you will need to have your action method return a full view as you cannot update a portion of the page without javascript turned on.

0
votes

You can use this sintax:

@Ajax.ActionLink(cat.CATNAME, "GetCats", new AjaxOptions { UpdateTargetId = "catlist-" + Model.Count })