asp.net-core-tag-helpers

How to use asp-for TagHelper combined with Reflection

强颜欢笑 提交于 2021-02-08 05:14:40
问题 I have a class Foo which contains a lot of properties, I'd like to iterate through all of them into a form. The website is built using ASP.NET Core 2.2 and Razor. How can I build a MemberExpression that asp-for TagHelper seems to expect using Reflection? I've read a couple of post about this on the Forum but none of the answer fits my need. The following snippet doesn't work. @model Foo; <h1>Foo Reflective filling example</h1> @foreach(var property in typeof(Foo).GetProperties()) { <p> <div

How to use asp-for TagHelper combined with Reflection

别等时光非礼了梦想. 提交于 2021-02-08 05:14:27
问题 I have a class Foo which contains a lot of properties, I'd like to iterate through all of them into a form. The website is built using ASP.NET Core 2.2 and Razor. How can I build a MemberExpression that asp-for TagHelper seems to expect using Reflection? I've read a couple of post about this on the Forum but none of the answer fits my need. The following snippet doesn't work. @model Foo; <h1>Foo Reflective filling example</h1> @foreach(var property in typeof(Foo).GetProperties()) { <p> <div

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=

How to set value in .net tag helper attribute using javascript?

蓝咒 提交于 2021-01-28 09:15:30
问题 I am trying to set parameter value read from a textbox on the page to this link: <a asp-action="RetrieveEmailRecipients" asp-route-clientnumber="getClientNumber()">Retrieve Email Recipients</a> And I have Javascript down somewhere else at the bottom of the page. But appreatly this is not the right way to pass value to MVC action method's parameter. What parameter ClientNumber read in action is whatever the string/value in asp-route-clientnumber, in this case the value is getClientNumber().

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

.netcore asp-for decimal loses decimal places

孤街浪徒 提交于 2020-06-16 05:31:20
问题 I am running into an issue where I am losing decimal places when using the asp-for tag helper in my view. It seems to always round up to 2 decimals, while I want to have it round up to 3 decimals (in this case). I can see in my debugger that the value in the Model has 3 decimal places as e But then in my view, it's being displayed as 1.28 instead of 1.275 : This is my form's view, as you can see there's nothing special really going on (the asp-has-error tag helper is a custom tag helper for

View Component as a Tag Helper does not get Invoked

£可爱£侵袭症+ 提交于 2020-05-26 02:36:21
问题 Invoking a View Component as a Tag Helper was introduced in ASP.NET Core 1.1. (See “Invoking a view component as a Tag Helper”). But the following only returns the Test for VC part of the view. It seems that <vc:annual-orders>…</vc:annual-orders> part does not get invoked at all. Views\Shared\Components\AnnualOrders\Default.cshtml : @{ Layout = ""; } <div>Test for VC</div> <div> <vc:annual-orders> </vc:annual-orders> </div> myProj\ViewComponents\AnnualOrdersViewComponent.cs : public class

.NET Core <select> With Default Value?

本秂侑毒 提交于 2020-05-09 02:20:08
问题 My goal is to generate a <select> dropdown with a certain select value ( <option> ) pre-selected , so the finalized HTML should look like this: <select> <option value = "1">Option1</option> <option value = "2" selected>Option2</option> <option value = "3">Option3</option> </select> Note that the option with a value of 2 has a selected attribute, indicating that it will show before the dropdown is clicked. I cannot (and am trying to) achieve this using .NET Core Tag Helpers. This is my model

How to bind a ModelExpression to a ViewComponent in ASP.NET Core?

自闭症网瘾萝莉.ら 提交于 2020-03-20 06:05:41
问题 I would like to bind a model expression (such as a property) to a view component—much like I would with an HTML helper (e.g., @Html.EditorFor() ) or a tag helper (e.g., <partial for /> )— and reuse this model in the view with nested HTML and/or tag helpers. I am able to define a ModelExpression as a parameter on a view component, and retrieve a lot of useful metadata from it. Beyond this, I start running into roadblocks: How do I relay and bind to the underlying source model to e.g. an asp