asp.net-core-tag-helpers

How Do I Pass an Array of Values via Anchor Tag Helper?

流过昼夜 提交于 2019-12-13 07:52:52
问题 I'm using Asp.Net Core 2.1 Pages public async Task OnGetAsync([FromQuery(Name = "status")] string[] myValues) { } I'm trying to pass in an array of values from an anchor tag helper , but all I receive in myValues is one item. If I manually type out the query string to mirror MyRoute?myValues=A&myValues=B , it works as expected. I've tried the following with no success. <a asp-page="/MyPage" asp-route-status="A" asp-route-status="B">Click</a> <a asp-page="/MyPage" asp-route-status="new [] { A,

ASP.Net Core Conditional Class Tag Helper

天涯浪子 提交于 2019-12-11 17:25:10
问题 When implementing the solution to an existing question for a conditional class tag helper in ASP.Net Core 2.0 I am not getting the expected results. The tag helper is a direct copy from the posted answer and has not been modified. Following the example instead of the class name I'm getting the full attribute name along with the specified class. What am I doing wrong? TagHelper using Microsoft.AspNetCore.Razor.TagHelpers; using System; using System.Collections.Generic; using System.Linq;

How can I make a fancy checkbox template for ASP.NET Core?

偶尔善良 提交于 2019-12-11 01:58:47
问题 I've got a lot of boolean s in my model, and we're using Bootstrap, so for every boolean property I'm copy/paste refactoring: <div class="form-group"> <div class="custom-control custom-checkbox "> <input asp-for="IsFoo"/> <label asp-for="IsFoo"></label> </div> </div> ... but that's dumb. I tried adding this to Views/Shared/EditorTemplates/bool.cshtml : @model bool? <div class="form-group"> <div class="custom-control custom-checkbox "> <input asp-for="@Model"/> <label asp-for="@ViewData

Tag helper order of execution

夙愿已清 提交于 2019-12-10 22:16:34
问题 I am writing a set of ASP.Net Core tag helpers that target (among other tags) <form> and <input> tags. My <form> tag helper defines a custom attribute, the value of which it wants to pass to the child elements. All of the articles I've read make this sound simple: The parent tag helper stores the value in the context.Items dictionary, and the children read it from that same dictionary. This implies that the child tag helpers execute after the parent tag helper. However, I've discovered that,

How to use TagHelpers in Blazor?

巧了我就是萌 提交于 2019-12-10 16:39:19
问题 I created a tag helper and wanted to use that in my Blazor sample project. However, when I want to use the tag helper, the compiler complains about that: CS0103 The name 'StartTagHelperWritingScope' does not exist in the current context FirstBlazorApp . What is additionally required to make tag helpers work in Blazor? 回答1: Tag helpers are not supported in Blazor. At least not as of now. 回答2: On A blazor page you would use a blazor component, this is like a TagHelper but it runs client side

Is it possible to pass ModelExpression to a TagHelper?

冷暖自知 提交于 2019-12-10 04:26:43
问题 We can get a ModelExpression using this property in a TagHelper: [HtmlAttributeName("asp-for")] public ModelExpression For { get; set; } I somehow managed* to have a ViewModel wich has a ModelExpression property: public class TemplateViewModel { public ModelExpression For { get; set; } } Everytime I try to pass it, the Model expression is For from TemplateViewModel , not the real Expression wich is stored into For : @model TemplateViewModel <input asp-for="@Model.For" class="form-control"/>

Is there any way to create looping with Tag Helpers?

孤街浪徒 提交于 2019-12-09 10:21:16
问题 Is there any way to create a Tag Helper that somehow iterates (repeater like) over the inner tag helpers? That is, something like: <big-ul iterateover='x'> <little-li value='uses x somehow'></little-li> </bg-ul> I know I can do it with razor foreach but trying to figure out how to do it without having to switch to c# code in my html. 回答1: It's possible, by using the TagHelperContext.Items property. From the doc: Gets the collection of items used to communicate with other ITagHelpers . This

Custom tag helper not working

心不动则不痛 提交于 2019-12-09 05:04:02
问题 I followed a few guides on creating a custom tag helper for ASP Core. This is my helper: using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; using System; namespace ToolControlSystem.TagHelpers { [HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)] public class DescriptionTagHelper : TagHelper { private const string DescriptionAttributeName = "asp-for"; [HtmlAttributeName

Select ENUM Tag Helper in ASP.NET Core MVC

拥有回忆 提交于 2019-12-07 15:46:21
问题 I need some help with an ENUM dropdown using Tag Helper. I found lots exemples binding a model to Selectlist and some using ENUM but all of them, about CREATE action, and Im facing problems with EDIT action. MY MODEL public class ProspectLog { public int Id { get; set; } public int IdProspect { get; set; } public int IdEmpresa { get; set; } public DateTime Criado { get; set; } public string Usuario { get; set; } public string Descricao { get; set; } public ETipoLog TipoLog { get; set; }

Select ENUM Tag Helper in ASP.NET Core MVC

五迷三道 提交于 2019-12-05 21:02:00
I need some help with an ENUM dropdown using Tag Helper. I found lots exemples binding a model to Selectlist and some using ENUM but all of them, about CREATE action, and Im facing problems with EDIT action. MY MODEL public class ProspectLog { public int Id { get; set; } public int IdProspect { get; set; } public int IdEmpresa { get; set; } public DateTime Criado { get; set; } public string Usuario { get; set; } public string Descricao { get; set; } public ETipoLog TipoLog { get; set; } public enum ETipoLog { [Display(Name = "CADASTRO")] Cadastro = 0, [Display(Name = "CONTATO")] Contato = 1,