Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Feature: Support "this" context for ajax actions/forms [1487]

$
0
0
Copied from: https://aspnet.codeplex.com/workitem/10335, opened by: AaronLS

In handlers such as OnSuccess for Ajax.BeginForm or Ajax.ActionLinkl, there is no way to determine the submitting element. This is a pretty common scenario when creating reusable ajax controls. Partials pages provide a great way to create reusable ajax controls, but when there are multiple of that partial on a page, your callback functions have no way to determine which of the many elements was the element which submitted the request. It is usually necesary to identify a relative element for where the results of the ajax are to be placed. Using traditional jquery .ajax() you can do things like this.closest(...).find('.updateHere'). Without a "this" context you cannot do this at all, making the MVC Ajax helpers useless in many of the scenarios I encounter on a daily basis.

Notice that this question has over 3000 views at the time I am posting this:
http://stackoverflow.com/a/14611314/84206

So please do not claim that "it is not a common scenario" and close the issue simply for that reason.


Comment1:
I would love to see this added as well. For clarity, what we want is for the jQuery Unobtrusive Ajax library to set the context of jQuery's options so that while within the event handlers for OnSuccess, OnComplete, etc... the 'this' keyword maps to the source element. It's natively supported by jQuery, we just need the one line added. We can do it ourselves but when using Nuget future changes would overwrite our modification and we believe it would benefit others as well.

Adding a change to around line# 100 would do it.
options.data.push({ name: "X-Requested-With", value: "XMLHttpRequest" });

options.context = element; // <--- Add this line

method = options.type.toUpperCase();
if (!isMethodProxySafe(method)) {
options.type = "POST";
options.data.push({ name: "X-HTTP-Method-Override", value: method });
}

comment 2:
Adding this one line definitely helped us out, but it's ugly having a .custom.js file (and difficult to maintain over time). It would be great to to see this added. It makes the whole unobtrusive ajax so much more useful.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>