"system.web.mvc.ajaxhelper"在哪里?在asp.net core 1.0中

编程入门 行业动态 更新时间:2024-10-13 04:23:38
本文介绍了"system.web.mvc.ajaxhelper"在哪里?在asp core 1.0中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I´m trying out the new asp 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中

本文发布于:2023-11-06 08:22:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563178.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:web   mvc   quot   system   ajaxhelper

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!