asp.net-core-tag-helpers

Is it possible to pass ModelExpression to a TagHelper?

…衆ロ難τιáo~ 提交于 2019-12-05 08:19:00
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"/> Above results in: <input class="form-control" type="text" id="For" name="For" value="Microsoft

Is it possible to call ViewComponent from custom TagHelper?

和自甴很熟 提交于 2019-12-04 10:07:51
问题 I'm writing a custom TagHelper and want to render a ViewComponent inside it. Something similar to what vc:xyz tag helper does, but in a more controlled way, so that I can determine at runtime which ViewComponent to render. Is it possible? 回答1: In order to do that, you need to inject IViewComponentHelper into your TagHelper, contextualize it and then use it to render any ViewComponent depending on your application logic. Here is a quick illustration: [HtmlTargetElement("widget", Attributes =

Asp.Net core 2.0 MVC anchor tag helper not working

删除回忆录丶 提交于 2019-12-04 03:35:07
问题 I am trying to create a demo page, and can't solve the next problem, and I tried everything what I found on the web. I have an anchor tag with tag helper: <a class="menu-link" asp-area="" asp-controller="Telefon" asp-action="Index">Telefonok</a> I also added a _ViewImports.cshtml and in it I added as I saw in the net @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" , but I still got an error: The name 'addTagHelper' does not exist in the current context What did I wrong?! 回答1: There are two

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

半世苍凉 提交于 2019-12-03 15:16:44
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 [Display(Name = "First Name")] to simply insert a space between words. It would make sense that Tag

Is there any way to create looping with Tag Helpers?

痴心易碎 提交于 2019-12-03 12:45:19
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. It's possible, by using the TagHelperContext.Items property. From the doc : Gets the collection of items used to communicate with other ITagHelpers . This System.Collections.Generic.IDictionary<TKey, TValue> is copy-on-write in order to ensure items added to this

Custom tag helper not working

白昼怎懂夜的黑 提交于 2019-12-03 04:36:35
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(DescriptionAttributeName)] public ModelExpression Model { get; set; } public override void Process(TagHelperContext

Is it possible to call ViewComponent from custom TagHelper?

核能气质少年 提交于 2019-12-03 04:03:12
I'm writing a custom TagHelper and want to render a ViewComponent inside it. Something similar to what vc:xyz tag helper does, but in a more controlled way, so that I can determine at runtime which ViewComponent to render. Is it possible? In order to do that, you need to inject IViewComponentHelper into your TagHelper, contextualize it and then use it to render any ViewComponent depending on your application logic. Here is a quick illustration: [HtmlTargetElement("widget", Attributes = WidgetNameAttributeName)] public class WidgetTagHelper : TagHelper { private const string

Asp.Net core 2.0 MVC anchor tag helper not working

两盒软妹~` 提交于 2019-12-01 21:21:21
I am trying to create a demo page, and can't solve the next problem, and I tried everything what I found on the web. I have an anchor tag with tag helper: <a class="menu-link" asp-area="" asp-controller="Telefon" asp-action="Index">Telefonok</a> I also added a _ViewImports.cshtml and in it I added as I saw in the net @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" , but I still got an error: The name 'addTagHelper' does not exist in the current context What did I wrong?! There are two _ViewImports.cshtml, you probably need the one located in the Views Folder. In my project I have a another

How to create a script tag helper that inherits from the standard .Net Core script tag helper

余生颓废 提交于 2019-12-01 11:56:05
I maintain a large legacy ASP.NET MVC application, which was recently converted to .Net Core. I need to introduce cache busting for our JavaScript and CSS files. I appreciate this can easily be done using the asp-append-version="true" attribute on the new .Net Core script tag helper. However, my application has script tags in over a 100 places. Adding the attribute in all those places will touch large numbers of pages, which means a lot of regression testing. Is there a way to create a new script tag helper that inherits from the .Net Core script tag helper, and that always has the asp-append

Append QueryString to href in asp.net core Anchor Helper Tag

夙愿已清 提交于 2019-11-29 14:04:36
I am trying to add anything in the query of the request to anchors in the html result: Fictitious example: User makes a request (note that band and song could be anything, I have a route catering this request: template: "{band}/{song}"): http://mydomain/band/song?Param1=111&Param2=222 Now I want my anchors to append the query string part to the href of my anchors. So I tried something like this (note the 'asp-all-route-data'): <a asp-controller="topic" asp-action="topic" asp-route-band="iron-maiden" asp-route-song="run-to-the-hills" asp-all-route-data="@Context.Request.Query.ToDictionary(d=>d