tag-helpers

How can I pass string value for “asp-for” in asp net 5

我是研究僧i 提交于 2019-12-18 03:38:29
问题 I want to write a Edit.cshtml file for an entity with many properties to edit, so I have to write the following codes many times: <div class="form-group"> <label asp-for="Email" class="col-md-2 control-label"></label> <div class="col-md-10"> <input asp-for="Email" class="form-control" /> <span asp-validation-for="Email" class="text-danger"></span> </div> </div> Actually, there are many entities so that I have to write many Edit.cshtml files. I want to make some simplifications I want to

Nesting TagHelpers in ASP.NET Core MVC

*爱你&永不变心* 提交于 2019-12-17 16:35:24
问题 The ASP.NET Core TagHelper documentation gives the following example: public class WebsiteContext { public Version Version { get; set; } public int CopyrightYear { get; set; } public bool Approved { get; set; } public int TagsToShow { get; set; } } [TargetElement("website-information")] public class WebsiteInformationTagHelper : TagHelper { public WebsiteContext Info { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagName = "section";

Why does Razor Pages scaffolding use HTML Helpers (and not Tag Helpers) for Index, Details and Delete pages?

我怕爱的太早我们不能终老 提交于 2019-12-13 03:07:44
问题 I recently started my first project using Razor Pages, I am using EF Core and have scaffolded all of my models into CRUD Razor Pages. Something I noticed was that the Create and Edit Razor Pages that are generated use Tag Helpers to display the data. i.e. <div class="form-group"> <label asp-for="ViewModel.Name" class="control-label"></label> <input asp-for="ViewModel.Name" class="form-control" /> <span asp-validation-for="ViewModel.Name" class="text-danger"></span> </div> Whereas the Index,

MVC6 attribute routing with two parameters

前提是你 提交于 2019-12-12 20:39:58
问题 I've had a look around for this and nothing that pertains to the MVC6 taghelper anchor tag in relation to having an alternative [HttpGet] method that caters for multiple parameters. Sure you can add multiple parameters to a MVC6 anchor taghelper but how do you process the second option with two parameters using attrubute routing... I have two [HttpGet] IactionResult methods: //GET: UserAdmin public async Task<IActionResult> Index() { return View(await _userAdminService.GetAllUsers("name_desc"

How to get value of id in Url from Razor View in ASP.NET Core

╄→尐↘猪︶ㄣ 提交于 2019-12-12 10:36:46
问题 I have a simple ASP.NET Core web application with a page like such http://localhost:5050/Posts/Create/3 . In my Razor View Views/Posts/Create.cshtml , how would I be able to get the value "3" so that I can create a link like <a href="/Blogs/Details/3">« Back to Blog</a> ? So far, created the link using the following Tag Helper, but I don't know what to put for asp-route-id : <a asp-controller="Blogs" asp-action="Details" asp-route-id="" class="btn btn-default btn pull-right">« Back</a> I am

Custom Tag helper debugging

这一生的挚爱 提交于 2019-12-12 06:25:27
问题 I'm trying to test a new tag helper that I'm trying to create. I've stumbled into a shortcoming of the new .net core validation and cannot change the class post validation. So if I wanted to give my errors a red background, the span is always there and won't change. So, I've decided to make my own tag helper. the problem is I can't seem to get it to work or trigger. I can't even get it to hit a break point. Here is what I have for a tag helper so far. namespace MusicianProject.TagHelpers { //

Enclose a list of tags (taghelper) by a parent tag

做~自己de王妃 提交于 2019-12-11 14:49:56
问题 I need to achieve like below <MyTagList> <MyTag></MyTag> <MyTag></MyTag> </MyTagList> When ever I use MyTag in design time, it need to be enclosed automaticaly by MyTagList or MyTag should error that it must be enclosed by MyTagList 回答1: You can't do this today at design time. You can however do it partially at runtime by utilizing TagHelperContext.Items . By using the Items property you can ensure that each tag is enclosed by a parent tag and throw if it's not. Insert an indicator into the

Asp .Net Core Bootstrap 4 Tabs tag helper

拜拜、爱过 提交于 2019-12-11 14:32:41
问题 I'm trying to render this <nav> <div class="nav nav-tabs" id="nav-tab" role="tablist"> <a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Home</a> <a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</a> <a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role=

TagHelper validation when editing a list

我只是一个虾纸丫 提交于 2019-12-11 10:18:21
问题 I am trying to use TagHelpers when editing a list of items. This is the code inside the view where helpers are employed: @for (var i = 0; i < Model.Items.Count; i++) { <tr> <td> <input asp-for="Items[i].Name" /> <span asp-validation-for="Items[i].Name" class="text-danger" /> </td> </tr> } Input helpers are working as expected, ModelState is properly filled with validation errors but validation errors are not shown to the user. I'm guessing there's a problem with rendering validation tags. <td

Updating related Phone entities with custom tag helper

好久不见. 提交于 2019-12-11 09:29:12
问题 As my application currently sits, each AppUser may (or may not) have 3 phone numbers ( UserPhones ). One of each type (Mobile, Home, Other). The following Tag Helper works great (Thanks @itminus). Calling code from Razor Page: <user-phones phones="@Model.UserPhones" asp-for="@Model.UserPhones" prop-name-to-edit="PhoneNumber" types-to-edit="new EnumPhoneType[] { EnumPhoneType.Mobile, EnumPhoneType.Other }" /> Code: public class UserPhonesTagHelper : TagHelper { private readonly IHtmlGenerator