asp.net-core-tag-helpers

Use Razor Tag helpers inside custom tag helper

雨燕双飞 提交于 2020-02-24 17:05:22
问题 Hello this is my tag helper [HtmlTargetElement("card")] public class CardTagHelper : TagHelper { public string Title { get; set; } public string Icon { get; set; } public string Url { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagName = "CardTagHelper"; output.TagMode = TagMode.StartTagAndEndTag; var preContent = new StringBuilder(); preContent.AppendFormat($@" <div class='card custom-card'> <div class='card-header'> <div class='card

How to use Attributes Property in HtmlTargetElement (Tag Helpers) to target one tag or another?

痴心易碎 提交于 2020-01-25 00:23:26
问题 I'm wrestling with understanding how to show the string assigned to Attributes in the HtmlTargetElement class attribute works. I have a couple questions that I think will highlight my issue and understanding. Let's say we want activate an Html Element only when make starts with gm and there is any model. I think there is a way to do this with a single class attribute (not multiple ones). I'm trying the following but it is just a SWAG and does not work. I'd appreciate tips so I can understand

Instantiating and Invoking TagHelpers Manually

两盒软妹~` 提交于 2020-01-06 07:59:30
问题 This is a follow up question to this question, which seems to be for an older ASP.NET Core version (I'm using 2.1). I'm trying to call a TagHelper manually from within a TagHelper. Applying the Answer in the linked question above, the TagHelper.Process looks like so: public override async void Process(TagHelperContext context, TagHelperOutput output) { var anchorTagHelper = new AnchorTagHelper { Action = "Home", }; var anchorOutput = new TagHelperOutput("a", new TagHelperAttributeList(),

Tag helper intellisense in VS 2017 ver 15.3.x not working

て烟熏妆下的殇ゞ 提交于 2020-01-03 17:03:36
问题 In past versions of Visual Studio 2017 if a developer wanted to have tag helper intellisense they needed to install Razor Language Services as indicated in this SO answer: ASP.NET Core Tag Helper Intellisense in Visual Studio 2017 In prior versions of VS 2017 I did this and it worked great. Recently I upgraded to Visual Studio 2017 version 15.3.2 from version 15.2 I believe and now my tag helper intellisense is no longer working. I read here https://developercommunity.visualstudio.com/content

Link tag helper not working in asp.net core 2.2

☆樱花仙子☆ 提交于 2019-12-22 17:45:33
问题 My link tag helpers are no longer working properly after migrating to asp.net core 2.2. <a class="btn btn-outline-primary" asp-controller="MyController" asp-action="MyAction" asp-route-id="@Id">Link</a> This works fine when I set the compatibility version to 2.1, but produces an empty href when set to compatibility version 2.2. <a class="btn btn-outline-primary" href="">Link</a> I followed the steps Migrate from ASP.NET Core 2.1 to 2.2 .SetCompatibilityVersion(CompatibilityVersion.Version_2_1

Display/Edit a Currency in ASP.NET MVC Core, why so complicated?

家住魔仙堡 提交于 2019-12-22 10:47:05
问题 In an ASP.NET Core 2.0 application, I have a Foo class with a lot of classical string or numeric members and also a int? Budget field. using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace MyProj.ViewModels { public class RecordEditViewModel { public RecordEditViewModel() { } public string Name { get; set; } public string Prop1 { get; set; } public string Prop2 { get; set; } public string Prop3 { get; set; }

ASP .Net Core Custom Tag Helper to Convert CamelCase Properties to spaces

我与影子孤独终老i 提交于 2019-12-21 04:58:13
问题 Is it possible in ASP.Net Core to automatically convert camel case property names in view models to insert spaces into the corresponding labels when using tag helpers? If my view model looks like this... [Display(Name = "First Name")] public string FirstName { get; set; } [Display(Name = "Last Name")] public string LastName { get; set; } [Display(Name = "Referral Date")] public DateTime ReferralDate { get; set; } It seems like a lot of extra configuration applying data annotations such as

Input Tag Helper Not Working with Razor Code

China☆狼群 提交于 2019-12-18 04:47:09
问题 I want to combine an input tag helper with razor code to set an attribute but I cannot get the two technologies to work together. I am simply trying to set the disabled attribute on the input field based on the value of view model property. When i put the razor code after the asp-for tag the razor intellisense is not recognized and the field is not disabled as expected... <input asp-for="OtherDrugs" @((Model.OtherDrugs == null) ? "disabled" : "") class="form-control" /> Rendered output...

How do ASP.NET Core's “asp-fallback-*” CDN tag helpers work?

只谈情不闲聊 提交于 2019-12-18 04:36:22
问题 I understand what the asp-fallback-* tag helpers do. What I don't understand is how. For example: <link rel="stylesheet" href="//ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/css/bootstrap.min.css" asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css" asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" /> This loads bootstrap from the CDN, and loads the local copy if the CDN is down. But how does it decide to do that? I assume it

ASP.Net Core 2.1 MVC SelectList in View is not getting populated

﹥>﹥吖頭↗ 提交于 2019-12-13 08:06:40
问题 I am working on an ASPNet Core 2.1 MVC website and I am trying to get a select list to populate with a list of Companies (value = Id, text = CompanyName). I can see that the data exists in the List in the ViewModel but no matter what I try, I can't get the data to show in the dropdown list in the view. I am following the first variation of the SelectList recommendation from this SO post Here is my EditSite ViewModel class public class EditSite { public int Id { get; set; } [Required]