tag-helpers

TagHelper cached output by calling GetChildContentAsync() and Content.GetContent()

前提是你 提交于 2019-12-22 10:35:07
问题 According to this article if we use several tag helpers(targeted to the same tag) and in each of them we will use await output.GetChildContentAsync() to recieve html content we will come to the problem with cached output: The problem is that the tag helper output is cached, and when the WWW tag helper is run, it overwrites the cached output from the HTTP tag helper. The problem is fixed by using statement like: var childContent = output.Content.IsModified ? output.Content.GetContent() :

How to use fallback source on ScriptTagHelper and LinkTagHelper correctly

≡放荡痞女 提交于 2019-12-22 08:34:01
问题 I have read following posts from Damian Edwards. https://github.com/aspnet/Mvc/issues/1576 https://github.com/aspnet/Mvc/issues/1580 At the ScriptTagHelper , I'm not sure what I should enter on asp-fallback-test attribute ? It's the same as for jQuery ? window.jQuery ? How do I find the correct JavaScript Expression? Can someone give me an example based on moment-withlocales.min.js ? Thanks! Is following example for the LinkTagHelper correct? <link rel="stylesheet" href="https://cdn.jsdelivr

How to render a Razor template inside a custom TagHelper in ASP.NET Core?

不打扰是莪最后的温柔 提交于 2019-12-22 08:30:27
问题 I am creating a custom HTML Tag Helper: public class CustomTagHelper : TagHelper { [HtmlAttributeName("asp-for")] public ModelExpression DataModel { get; set; } public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { string content = RazorRenderingService.Render("TemplateName", DataModel.Model); output.Content.SetContent(content); } } How to render a partial view programatically an get the rendered content as a string inside TagHelper.ProcessAsync ? Should

Should my custom ASP.Net 5 MVC 6 Tag Helpers have an asp- prefix?

好久不见. 提交于 2019-12-21 14:06:12
问题 I've been reading about the new support for Tag Helpers in MVC 6 and now need to create my own. I see that the built in tag helpers for existing HTML elements are all prefixed with "asp-" For example: <a asp-controller="Home" asp-action="Index">Home</a> But what about my own custom tag helpers. Should I also prefix those with "asp-" to show that it is running on the server. Or should this be reserved for framework attributes? Should I create my own project/company named prefix instead? Is

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

TagHelper for passing route values as part of a link

房东的猫 提交于 2019-12-20 09:56:11
问题 When specifying asp-controller and asp-action on a link, what's the syntax for also passing an id attribute? E.g. If I wanted to link to the edit URL for a given object, the required URL would be /user/edit/5 for example. Is there a method to achieve this using TagHelpers, or do we still have to fall back to @Html.ActionLink() ? 回答1: You can use the attribute prefix asp-route- to prefix your route variable names. Example: <a asp-action="Edit" asp-route-id="10" asp-route-foo="bar">Edit</a> 回答2

Setting ASP.NET Core TagHelper Attribute Without Encoding

こ雲淡風輕ζ 提交于 2019-12-20 04:53:55
问题 I want to add the integrity attribute to a script tag in my tag helper. It contains a + sign which I don't want encoded. <script integrity="sha384-Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7"></script> This is my tag helper: [HtmlTargetElement(Attributes = "script")] public class MyTagHelper : TagHelper { public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { // Omitted... output.Attributes["integrity"] = "sha384

Tag Helpers disabled in VS 2015

妖精的绣舞 提交于 2019-12-19 19:56:16
问题 I am having trouble getting Tag Helpers enabled in my project. Here is a summary of the project setup: VS 2015 RC Community Edition. Project.json reference: Microsoft.AspNet.Mvc": "6.0.0-beta4 _GlobalImport.chtml has @addTagHelper"*,Microsoft.AspNet.Mvc.TagHelpers" No build errors or warnings. Must missing something, but I don't know what. UPDATE: Seems I am part of the way there. I added @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" to the _ViewStart.chtml. Razor is now processing

Tag Helpers - Self closing HTML tags is a bad habit?

故事扮演 提交于 2019-12-19 09:00:01
问题 I am incorporating TagHelpers in my MVC vNext project, and I realized they don't work when I self close the HTML tags. @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" <label asp-for="FirstName"/> <!-- self closing tag --> <span asp-validation-for="FirstName"/> <!-- self closing tag --> And, insteand when I put the closing tags, I see the values being displayed. <label asp-for="FirstName"></label> <span asp-validation-for="FirstName"></span> Generated HTML <label for="FirstName">FirstName<

.Net Core tag helper intellisense and color coding not working

感情迁移 提交于 2019-12-18 03:57:14
问题 I am having issues with .NET core and tag helpers. The color coding and the intellisense are not displaying or being registered when I type in asp-for. I've tried creating a new solution in a separate instance, verified that the intellisense works, and then copied the project.json into the project that doesn't have working intellisense/color coding, and it doesn't fix the issue. Here is my project.json { "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" },