"system.web.mvc.ajaxhelper"在哪里?在asp.net core 1.0中 [英] Where is "system.web.mvc.ajaxhelper" in asp.net core 1.0

查看:44
本文介绍了"system.web.mvc.ajaxhelper"在哪里?在asp.net core 1.0中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在"rc1-final"上尝试新的asp.net 5(现在是1.0版核心),但直到Asp.Net 4位于"system.web.mvc"时,我才发现旧类AjaxHelper."dll.

I´m trying out the new asp.net 5 (core 1.0 now) on the "rc1-final" and I´m not finding the old class AjaxHelper that until Asp.Net 4 was at "system.web.mvc" dll.

是否有包含此类的nuget软件包?还是其他任何可以替代此功能的东西?

我正在使用"DNX 452",现在不假装移至"core 1.0"/"dnx 5".

I´m using the "DNX 452" and do not pretend to move to "core 1.0"/"dnx 5" right now.

推荐答案

mvc ajaxhelpers主要只是设置jquery不占优ajax使用的data-ajax- *属性.您只需在标记中添加属性,即可在ASP.NET Core中轻松,轻松地完成此操作,或者,如果您想了解它,可以实现taghelpers.例如,在较旧的MVC 5中,我曾经使用ajaxhelper来实现自定义引导模态对话框.当我将其移植到ASP.NET Core时,我像您一样发现ajaxhelpers不存在,因此我实现了一个taghelper,它添加了如下的ajax属性:

The mvc ajaxhelpers are mainly just setting up the data-ajax-* attributes that are used by jquery unobtrusive ajax. You can easily and more cleanly do that in ASP.NET Core just by adding the attributes in the markup, or if you want to be fancy about it you can implement taghelpers. For example in the older MVC 5 I used to use ajaxhelper to implement a custom bootstrap modal dialog. When I went to port that to ASP.NET Core I found like you that ajaxhelpers don't exist so I implemented a taghelper that adds the ajax attributes like this:

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

    }
}

这篇关于"system.web.mvc.ajaxhelper"在哪里?在asp.net core 1.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆