tag-helpers

Trigger TagHelper from another TagHelper

落爺英雄遲暮 提交于 2019-12-11 06:03:50
问题 I would like to trigger the stock ScriptTagHelper (view source on GitHub) so that it would emulate the asp-append-version="true" attribute. I know that the proper way to use this is to just change from this: <script src="somefile.js"></script> to this: <script src="somefile.js" asp-append-version="true"></script> This process is very similar for versioning CSS includes and images ( LinkTagHelper and ImageTagHelper ). Since I have a lot of included scripts, stylesheets, and images, I would

In AspNet.Core the Tag Helper asp-area doesn't work

淺唱寂寞╮ 提交于 2019-12-11 05:39:00
问题 I recently updated the Visual Studio for Update 3 and ASP.Net Core for 1.0.0. I followed the tutorial in documentation and I tried set up for use Areas like this https://docs.asp.net/en/1.0.0/mvc/controllers/areas.html However, the link generated was http://localhost:2187/?area=Admin, instead of http://localhost:2187/Admin/Home/Index Update My routes: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "areaRoute

Why is asp-route-id not working in my form post?

删除回忆录丶 提交于 2019-12-11 05:09:48
问题 I have asp-route-id working in one instance: It works from an anchor tag like this: <a id="editModal" data-toggle="modal" data-target="#modal_box" class="btn btn-sm btn-primary" asp-action="Edit" asp-route-id="@user.Id">Edit</a> and is received like this: public async Task<PartialViewResult> DeleteConfirm(string Id) => PartialView("_DeleteConfirm", await _userManager.FindByIdAsync(Id)); This method receives the correct id. The next example has the route id in the form tag like this: <div

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

Is it possible to set radio button tag helper value attribute as “checked” in html?

孤人 提交于 2019-12-10 18:29:00
问题 I was looking for a way to use the value attribute on radio button tag helper to inform if the button was checked or not, instead of using a separate field for selection. I found an answer by @Shyju to a related question. I am using a modified example of that answer to show what I mean. Let's say I have a viewmodel public class ExampleViewModel { public int Id { get; set; } public string UserName { get; set; } public List<UserRole> Roles { get; set; } } public class UserRole { public int Id {

MVC 6 Tag Helpers and foreach

感情迁移 提交于 2019-12-08 23:17:52
问题 What would I give to asp-for property of a label tag helper in order to display items from a collection. The code below generates a compilation error. @foreach (var item in Model) { <label asp-for="item.BookingCode"></label> } 回答1: The @ character escapes the default model lambda code. Therefore you can type: @foreach (var item in Model) { <label asp-for="@item.BookingCode"></label> } 回答2: I Have a simple way to do a list and show properties of it. List<string> razones = new List<string>();

ASP.NET mvc View with IEnumerable model and input tag helper

妖精的绣舞 提交于 2019-12-07 03:19:40
问题 In this official ASP.NET Core tutorial, I can use an Input Tag Helper as shown below. But due to a known model binding issue of form elements in a foreach loop, I want to use for loop instead. Question : If I were to replace @foreach (var item in Model) with @for (int i=0; i < Model.Count(); i++) in the following View . What would be my asp-for in <input asp-for="???" /> ? For some reason, intellisense is not recognizing, e.g, Model[i].BlogId or @Model[i].BlogId @model IEnumerable

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

半城伤御伤魂 提交于 2019-12-06 03:31:45
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() : (await output.GetChildContentAsync()).GetContent(); Description of this behaviour: The code above checks to

How to use fallback source on ScriptTagHelper and LinkTagHelper correctly

霸气de小男生 提交于 2019-12-05 14:21:05
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.net/bootstrap.daterangepicker/2/daterangepicker.css" asp-fallback-href="~/lib/bootstrap-daterangepicker

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

柔情痞子 提交于 2019-12-05 12:20:44
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 I request the injection of an IHtmlHelper ? Is it possible to get a reference to the razor engine ? It