Created
February 16, 2014 22:50
-
-
Save cbskgc/9041797 to your computer and use it in GitHub Desktop.
Supporting ReplaceWith for AjaxOption.InsertionMode: It is occasionally convenient to be able to update content including the target container. This avoids a separate container to wrap the partial view statement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
var ajaxOptions = new AjaxOptions { UpdateTargetId = "form" }; | |
var htmlAttributes = new { id = "form", data_ajax_mode = "replacewith" }; | |
} | |
@using (Ajax.BeginForm("Index", null, ajaxOptions, htmlAttributes)) | |
{ | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncOnSuccess(element, data, contentType) { | |
var mode; | |
if (contentType.indexOf("application/x-javascript") !== -1) { | |
return; | |
} | |
mode = (element.getAttribute("data-ajax-mode") || "").toUpperCase(); | |
$(element.getAttribute("data-ajax-update")).each(function (i, update) { | |
var top; | |
switch (mode) { | |
case "BEFORE": | |
top = update.firstChild; | |
$("<div />").html(data).contents().each(function () { | |
update.insertBefore(this, top); | |
}); | |
break; | |
case "AFTER": | |
$("<div />").html(data).contents().each(function () { | |
update.appendChild(this); | |
}); | |
break; | |
case "REPLACEWITH": | |
$(update).replaceWith(data); | |
break; | |
default: | |
$(update).html(data); | |
break; | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function h(c,b,e){var d;if(e.indexOf("application/x-javascript")!==-1)return;d=(c.getAttribute("data-ajax-mode")||"").toUpperCase();a(c.getAttribute("data-ajax-update")).each(function(f,c){var e;switch(d){case"BEFORE":e=c.firstChild;a("<div />").html(b).contents().each(function(){c.insertBefore(this,e)});break;case"AFTER":a("<div />").html(b).contents().each(function(){c.appendChild(this)});break;case"REPLACEWITH":a(c).replaceWith(b);break;default:a(c).html(b)}})} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment