2016-05-13 14 views
0

"rc1-final"で新しいasp.net 5(コア1.0)を試しています。 Asp.Net 4が "system.web.mvc" dllにあったまでの古いクラスのAjaxHelper。asp.netコア1.0の "system.web.mvc.ajaxhelper"はどこですか?

このクラスを含むナゲットパッケージはありますか?またはこれを代用する他のもの?

私は "DNX 452"を使用していますが、現在 "core 1.0"/"dnx 5"に移動しているようなふりをしていません。

+1

https://github.com/aspnet/:私はajaxhelpersはそれほど存在しないことをASP.NETコアに、私はあなたのような見つけポートに行ったとき、私はアヤックスはこのように属性を追加しtaghelperを実装しましたMvc/issues/2015はまだサポートされていませんが、私が見ることができる範囲まではありません – MarkB

答えて

2

mvc ajaxhelpersは、主にjquery unobtrusive ajaxによって使用されるdata-ajax- *属性を設定しています。マークアップに属性を追加するだけで、簡単にASP.NET Coreで簡単に行うことができます。また、タグヘルパーを実装することもできます。たとえば、古いMVC 5では、カスタムブートストラップモーダルダイアログを実装するためにajaxhelperを使用しました。

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

    } 
} 
+0

ええ、私はその方法が唯一のものであることを発見しました。しかし、Taghelper(私の古いヘルパーに基づいて)から継承する代わりに、私はHtmlHelperの拡張を使用しています。 TagHelperのメリットは何ですか? –

+0

「taghelpersのメリット」をGoogleで検索すると、良い情報が見つかります。主に、より洗練されたマークアップとマークアップをC#からもっと洗練されたものからHtmlHelpersと区別することです。ここの良い例http://www.davepaquette.com/archive/2015/05/11/cleaner-forms-using-tag-helpers-in-mvc6.aspx –

関連する問題