Die mvc ajaxhelpers richten hauptsächlich nur die Daten-ajax- * Attribute ein, die von jquery dezenten Ajax verwendet werden. Sie können dies einfach und sauberer in ASP.NET Core tun, indem Sie einfach die Attribute im Markup hinzufügen, oder wenn Sie sich etwas einfallen lassen möchten, können Sie taghelpers implementieren. Zum Beispiel habe ich in der älteren MVC 5 mit ajaxhelper ein benutzerdefiniertes Bootstrap-Modaldialogfeld implementiert. Als ich in den Hafen ging, die ASP.NET-Core ich wie Sie festgestellt, dass ajaxhelpers existieren nicht so implementiert ich eine taghelper, dass die Ajax-Attribute wie folgt ergänzt:
/// <summary>
/// this taghelper detects the bs-modal-link attribute and if found (value doesn't matter)
/// it decorates the link with the data-ajax- attributes needed to wire up the bootstrap modal
/// depends on jquery-ajax-unobtrusive and depends on cloudscribe-modaldialog-bootstrap.js
/// </summary>
[HtmlTargetElement("a", Attributes = BootstrapModalLinkAttributeName)]
public class BootstrapModalAnchorTagHelper : TagHelper
{
private const string BootstrapModalLinkAttributeName = "bs-modal-link";
public BootstrapModalAnchorTagHelper() : base()
{
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
// we don't need to output this attribute it was only used for matching in razor
TagHelperAttribute modalAttribute = null;
output.Attributes.TryGetAttribute(BootstrapModalLinkAttributeName, out modalAttribute);
if (modalAttribute != null) { output.Attributes.Remove(modalAttribute); }
var dialogDivId = Guid.NewGuid().ToString();
output.Attributes.Add("data-ajax", "true");
output.Attributes.Add("data-ajax-begin", "prepareModalDialog('" + dialogDivId + "')");
output.Attributes.Add("data-ajax-failure", "clearModalDialog('" + dialogDivId + "');alert('Ajax call failed')");
output.Attributes.Add("data-ajax-method", "GET");
output.Attributes.Add("data-ajax-mode", "replace");
output.Attributes.Add("data-ajax-success", "openModalDialog('" + dialogDivId + "')");
output.Attributes.Add("data-ajax-update", "#" + dialogDivId);
}
}
https://github.com/aspnet/ Mvc/issues/2015 noch nicht unterstützt, kein Plan, soweit ich das sehen kann – MarkB