tag-helpers

Getting property attributes in TagHelpers

試著忘記壹切 提交于 2021-02-20 06:50:14
问题 Some of model properties has "Required" data annotation, that I need to read in a TagHelper class. public partial class Sale { [Required] public string CustomerId { get; set; } ... In the sales view I create a custom select for customer: <customer asp-for="CustomerId " value="@Model.CustomerId"></customer> And in the CustomerTagHelper class there is the process method: public override void Process(TagHelperContext context, TagHelperOutput output) { How can I discover at this point, if the

How to pass a value into partial tag helper? (ASP.NET Core)

淺唱寂寞╮ 提交于 2021-01-28 21:55:55
问题 I'm trying to render a partial view inside a form, I need to use the value of the loop (+1 of course because it starts at 0) as one of the values in my partial, any ideas how I can make this work? I've tried to do this with ViewData or ViewBag but either this is the wrong method or I'm implementing it wrong Here is my main form: @model Measurement <form asp-action="Create" method="post"> <div class="form-group" hidden> <label asp-for="LymphSiteId"></label> <input asp-for="LymphSiteId" value=

Anchor tag helper withing area folder not generating route area name MVC Core 3.1

橙三吉。 提交于 2020-07-10 07:00:43
问题 I have Areas in application. One area name is Admin and it has SchoolController inside its controller folder and Views inside Views\School folder . When I use anchor tag inside Views\School\Index.html it is not working i.e not generating href attribute but if I place the same tag on layout or any other razor page which is not inside area, it is generating href tag. Anchor tag is - <a class="nav-link text-dark" asp-area="Admin" asp-controller="School" asp-action="Index">School</a> Routing

ASP.NET Core Tag Helper Checkbox does not save unchecked value

帅比萌擦擦* 提交于 2020-02-05 02:33:26
问题 I'm adding a checkbox in an MVC form with Tag Helpers: <div class="form-group"> <label asp-for="@Model.Billable"></label> <input asp-for="@Model.Billable" type="checkbox" /> <input asp-for="@Model.Billable" type="hidden" /> </div> When the user changes the value to Checked from Unchecked, the form value passed back to the controller is True - perfect. However, if the value of the checkbox starts as Checked and the user changes it to Unchecked, the form value passed back to the controller is

.Net Core Security Trimming using Authorized Attribute on Controller Methods

吃可爱长大的小学妹 提交于 2020-01-25 06:50:21
问题 We just upgraded to .NET Core, and i'm trying to get things up and running with as little refactor as possible. All of our Security is handled by custom attribute decorations on controller methods. Kinda like this: [CustomAuthorize(Roles = "VIEWONLY, DEVELOPER, ADMIN, CHIEFADMIN") public ActionResult GetPage(string id){ return view; } Previously i had a custom HTMLHelper helping me do security trimming on Menu Links. It would check the controller action, and return true/false. Most of the

TagHelpers add custom class for LabelTagHelper based on validation attribute [Required]

北慕城南 提交于 2020-01-21 05:54:06
问题 In Core MVC there is anew concept as Tag helpers. We could previously create custom html helpers to attach some classes based on the validation data annotations such as [Required]. As TagHelpers arq quite new area I cannot find anough resources to achieve the following: here is the view model: [Required] public Gender Gender { get; set; } view: <label class="control-label col-md-3 required" asp-for="Gender"></label> css: .required:after { content: "*"; font-weight: bold; color: red; } output:

How to write a custom ASP.NET 5 taghelper that contains other taghelpers

大憨熊 提交于 2020-01-14 09:46:08
问题 I've been looking at examples on taghelpers on google but couldn't find any example I'm looking for. I have the following code: <div class="form-group"> <label asp-for="PersonName" class="col-md-2 control-label"></label> <div class="col-md-10"> <input asp-for="PersonName" class="form-control" /> <span asp-validation-for="PersonName" class="text-danger"></span> </div> </div> What i'd look to do is replace it with something like <bootstraprow asp-for="PersonName"></bootstraprow> However I'm not

Set Default/Null Value with Select TagHelper

馋奶兔 提交于 2020-01-12 02:55:09
问题 In asp.net mvc you can use: @Html.DropDownListFor(model => model.Category, ViewBag.Category as IEnumerable<SelectListItem>, "-- SELECT --", new { @class = "form-control" }) Using asp.net 5, how do I include the default or null value (-- SELECT --) in a taghelper: <select asp-for="Category" asp-items="@ViewBag.Category" class="form-control"></select> 回答1: You can just insert an option item inside the select: <select asp-for="Category" asp-items="@ViewBag.Category" class="form-control"> <option