public override void Process( Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { System.Reflection.PropertyInfo modelAttributesProperty = For.Metadata.GetType().GetProperty("Attributes"); Microsoft.AspNetCore.Mvc.ModelBinding.ModelAttributes modelAttributes = modelAttributesProperty.GetValue(For.Metadata) as Microsoft.AspNetCore.Mvc.ModelBinding.ModelAttributes ; object a = System.Linq.Enumerable.FirstOrDefault(modelAttributes.PropertyAttributes , m => m.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute) ); if (a is System.ComponentModel.ReadOnlyAttribute readOnlyAttribute && readOnlyAttribute.IsReadOnly == true) { Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute attribute = new Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("disabled", "disabled"); output.Attributes.Add(attribute); } base.Process(context, output); } // End Sub Process
public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); var content = await _helper.InvokeAsync("Summary", new { }); output.TagName = null; output.Content.SetHtmlContent(content); }
/* * // https://stackoverflow.com/questions/40850154/how-to-get-elements-defined-as-taghelper-content-in-taghelper-process * public override void Process(TagHelperContext context, TagHelperOutput output) * { * string c = output.Content.GetContent(); * // c is empty; how to get content "bla bla"? * } */ public override async Task ProcessAsync( Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { string c = (await output.GetChildContentAsync()).GetContent(); // transform markdown in c }
public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext __context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput __output) { (__helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); var __helperContent = await __helper.InvokeAsync("Test", ProcessInvokeAsyncArgs(__context)); __output.TagName = null; __output.Content.SetHtmlContent(__helperContent); }
public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); var content = await _helper.InvokeAsync("OnlineUsers", new { numbersToTake, minutesToTake, showMoreItemsLink }); output.TagName = null; output.Content.SetHtmlContent(content); }
} // EndConstructor // https://tahirnaushad.com/2017/08/27/asp-net-core-2-0-mvc-custom-tag-helpers/ public override void Process( Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { output.TagName = null; // output.TagName = "pre"; output.TagMode = Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag; System.Text.StringBuilder sb = new System.Text.StringBuilder(); string id = this.Id; string name = this.Name ?? id; string checkedValue = (AspFor == null) ? null : (string) System.Convert.ChangeType(AspFor.Model, typeof(string), System.Globalization.CultureInfo.InvariantCulture); int i = 0; foreach (Microsoft.AspNetCore.Mvc.Rendering.SelectListItem item in Items) { i++; sb.AppendLine("<label>"); sb.Append("<input type=\"checkbox\""); //sb.Append(" id=\"issue_custom_field_values_"); sb.Append(" id=\""); sb.Append(System.Web.HttpUtility.HtmlAttributeEncode(id)); sb.Append("_"); sb.Append(i); sb.Append("\""); //sb.Append(" name=\"issue[custom_field_values][3]\""); sb.Append(" name=\""); sb.Append(System.Web.HttpUtility.HtmlAttributeEncode(name)); sb.Append("_"); sb.Append(i); sb.Append("\""); sb.Append(" value=\""); sb.Append(System.Web.HttpUtility.HtmlAttributeEncode(item.Value)); sb.Append("\""); if (string.Equals(checkedValue, item.Value, System.StringComparison.InvariantCultureIgnoreCase)) { sb.Append(" checked=\"checked\" "); } sb.Append(">"); sb.AppendLine(System.Web.HttpUtility.HtmlEncode(item.Text)); sb.AppendLine("</label>"); } // Next item output.PostContent.SetHtmlContent(sb.ToString()); } // End Sub Process
// https://stackoverflow.com/questions/40001242/aspnetcore-get-path-to-wwwroot-in-taghelper public override void Process(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context , Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { EnsureFileVersionProvider(); Microsoft.AspNetCore.Mvc.IUrlHelper urlHelper = base.UrlHelperFactory.GetUrlHelper(this.ActionContext); // string myUrl = urlHelper.Content("~/somefilebelowwwwroot"); // string imgPath = output.Attributes["src"].Value as string; // Microsoft.AspNetCore.Html.HtmlString hs = output.Attributes["src"].Value as Microsoft.AspNetCore.Html.HtmlString; // string imgPath = hs.Value; // Microsoft.AspNetCore.Html.HtmlString hs = context.AllAttributes["src"].Value as Microsoft.AspNetCore.Html.HtmlString; // string imgPath = hs.Value; // var rcc = new Microsoft.AspNetCore.Mvc.Routing.UrlRouteContext(); // var rc = new Microsoft.AspNetCore.Routing.RouteContext(this.HttpContext); // lol = urlHelper.RouteUrl(rcc); string baseSrc = context.AllAttributes["src"].Value.ToString(); if (baseSrc.StartsWith("data:")) { return; } PathMap pm = PathMap.FromUrl(this.HostingEnvironment, urlHelper, baseSrc); System.IO.FileInfo fi = new System.IO.FileInfo(pm.Physical); string unixTicks = fi.Exists ? fi.LastWriteTimeUtc.ToUnixTicksString() : System.DateTime.UtcNow.ToUnixTicksString(); if (string.IsNullOrEmpty(pm.QueryString)) { baseSrc = $"{pm.Absolute}?no_cache={unixTicks}{pm.Hash}"; } else { baseSrc = $"{pm.Absolute}{pm.QueryString}&no_cache={unixTicks}{pm.Hash}"; } // No not have it XML-Attribute-encoded //output.Attributes.SetAttribute("src", new Microsoft.AspNetCore.Html.HtmlString(imgPath)); output.Attributes.SetAttribute("src", baseSrc); //output.Attributes.SetAttribute("src", src + "?&v=123"); // output.Attributes.SetAttribute(SrcAttributeName, _fileVersionProvider.AddFileVersionToPath(Src)); }
private Dictionary <string, object> ProcessInvokeAsyncArgs(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext __context) { Dictionary <string, object> args = new Dictionary <string, object>(); if (__context.AllAttributes.ContainsName("first-name")) { args[nameof(firstName)] = firstName; } return(args); }
public override void Process( Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context , Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { output.TagMode = Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing; output.TagName = null; // output.TagName = "pre"; output.Content.SetContent( System.IO.File.ReadAllText( System.IO.Path.Combine(_env.WebRootPath, this.Filename) ) ); }
public override void Process(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { Microsoft.AspNetCore.Mvc.IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext); Microsoft.AspNetCore.Mvc.Rendering.TagBuilder result = new Microsoft.AspNetCore.Mvc.Rendering.TagBuilder("div"); for (int i = 1; i <= PageModel.TotalPages; i++) { Microsoft.AspNetCore.Mvc.Rendering.TagBuilder tag = new Microsoft.AspNetCore.Mvc.Rendering.TagBuilder("a"); PageUrlValues["productPage"] = i; tag.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); if (PageClassesEnabled) { tag.AddCssClass(PageClass); tag.AddCssClass(i == PageModel.CurrentPage ? PageClassSelected : PageClassNormal); } tag.InnerHtml.Append(i.ToString()); result.InnerHtml.AppendHtml(tag); } output.Content.AppendHtml(result.InnerHtml); }
public override void Process(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { output.TagName = "a"; //a di anchor //Imposto i valori del link, indico all' anchor tag helper dove deve andare a navigare RouteValues["search"] = Input.Search; RouteValues["orderBy"] = OrderBy; RouteValues["ascending"] = (Input.OrderBy == OrderBy ? !Input.Ascending : Input.Ascending).ToString().ToLowerInvariant(); //Faccio generare l'output html all'AnchorTagHelper base.Process(context, output); //Aggiungo l'indicatore di direzione if (Input.OrderBy == OrderBy) { var direction = Input.Ascending ? "up" : "down"; output.PostContent.SetHtmlContent($" <i class=\"fas fa-caret-{direction}\"></i>"); //e tramite PostContent aggiungo l'icona rappresentante il senso di ordinamento } }
public override void Process(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { }
public override System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { throw null; }
public override void Init(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context) { }
public virtual void Init(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context) { }
public static bool TryDetermineMode <TMode>(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, System.Collections.Generic.IReadOnlyList <Microsoft.AspNetCore.Mvc.TagHelpers.ModeAttributes <TMode> > modeInfos, System.Func <TMode, TMode, int> compare, out TMode result) { throw null; }
// https://tahirnaushad.com/2017/08/27/asp-net-core-2-0-mvc-custom-tag-helpers/ public override void Process( Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) { // context.AllAttributes["maxlength"]; // System.Console.WriteLine(this.ActionContextAccessor.ActionContext.ModelState); // System.Console.WriteLine(this.ViewContext.ModelState); // System.Console.WriteLine(AspFor, AspItems); //foreach (string k in this.ViewContext.ModelState.Keys) //{ // System.Console.WriteLine(k); //} // output.TagName = "details"; // output.TagMode = TagMode.StartTagAndEndTag; //System.Text.StringBuilder sb = new System.Text.StringBuilder(); //sb.AppendFormat("<summary>{0}</summary>", this.AspItems); //sb.AppendFormat("<em>{0}</em>", this.AspFor); //sb.AppendFormat("<p>{0}</p>", this.AspItems); //sb.AppendFormat("<ul>"); //output.PreContent.SetHtmlContent(sb.ToString()); //output.PostContent.SetHtmlContent("</ul>"); output.TagName = null; // output.TagName = "pre"; output.TagMode = Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag; // output.PostContent.SetContent("<h1>this gets HTML encoded<h1>"); // output.PostContent.SetHtmlContent("<h1>Hello World</h1>"); System.Text.StringBuilder sb = new System.Text.StringBuilder(); //System.Collections.Generic.List< // Microsoft.AspNetCore.Mvc.Rendering.SelectListItem // > items = ( // System.Collections.Generic.List< // Microsoft.AspNetCore.Mvc.Rendering.SelectListItem // >)AspItems.Model; string id = this.Id; string name = this.Name ?? id; string checkedValue = (AspFor == null) ? null : (string) System.Convert.ChangeType(AspFor.Model, typeof(string), System.Globalization.CultureInfo.InvariantCulture); int i = 0; //foreach (Microsoft.AspNetCore.Mvc.Rendering.SelectListItem item in items) foreach (Microsoft.AspNetCore.Mvc.Rendering.SelectListItem item in Items) { i++; sb.AppendLine("<label>"); sb.Append("<input type=\"radio\""); //sb.Append(" id=\"issue_custom_field_values_"); sb.Append(" id=\""); sb.Append(System.Web.HttpUtility.HtmlAttributeEncode(id)); sb.Append("_"); sb.Append(i); sb.Append("\""); //sb.Append(" name =\"issue[custom_field_values][3]\""); sb.Append(" name=\""); sb.Append(System.Web.HttpUtility.HtmlAttributeEncode(name)); sb.Append("\""); sb.Append(" value=\""); sb.Append(System.Web.HttpUtility.HtmlAttributeEncode(item.Value)); sb.Append("\""); if (string.Equals(checkedValue, item.Value, System.StringComparison.InvariantCultureIgnoreCase)) { sb.Append(" checked=\"checked\" "); } sb.Append(">"); sb.AppendLine(System.Web.HttpUtility.HtmlEncode(item.Text)); sb.AppendLine("</label>"); } // Next item output.PostContent.SetHtmlContent(sb.ToString()); //output.PostContent.SetContent(""); //output.PreElement.SetHtmlContent("<h3>Hello</h3>"); } // End Sub Process