Где находится "system.web.mvc.ajaxhelper" в ядре asp.net 1.0

Я пробую новый asp.net 5 (сейчас ядро ​​1.0) на "rc1-final" и не нахожу старый класс AjaxHelper, который до Asp.Net 4 находился в dll "system.web.mvc".

Есть ли пакет nuget, содержащий этот класс? Или любой другой, который заменяет этот?

Я использую "DNX 452" и не претендую на переход к "core 1.0"/"dnx 5" прямо сейчас.

1 ответ

Решение

Ajaxhelpers mvc в основном просто устанавливают атрибуты data-ajax-*, которые используются ненавязчивым ajax jquery. Вы можете легко и аккуратно сделать это в ASP.NET Core, просто добавив атрибуты в разметку, или, если вы хотите, чтобы это было интересно, вы можете реализовать taghelpers. Например, в более старом MVC 5 я использовал ajaxhelper для реализации модального диалогового окна начальной загрузки. Когда я пошел перенести это в ASP.NET Core, я обнаружил, как вы, что ajaxhelpers не существует, поэтому я реализовал taghelper, который добавляет атрибуты ajax, как это:

/// <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);

    }
}
Другие вопросы по тегам