tag-helpers

How to render scripts, generated in TagHelper process method, to the bottom of the page rather than next to the tag element?

末鹿安然 提交于 2020-01-09 11:15:51
问题 I am generating scripts in process method of TagHelper class as follows [TargetElement("MyTag")] public Class MYClass: TagHelper{ public override void Process(TagHelperContext context, TagHelperOutput output) { StringBuilder builder = new StringBuilder(); builder.Append("<script>"); builder.Append("//some javascript codes here); builder.Append("</script>"); output.Content.Append(builder.ToString()); } } Now it place the script very next to the tag element as its sibling. I need to place the

How to render scripts, generated in TagHelper process method, to the bottom of the page rather than next to the tag element?

五迷三道 提交于 2020-01-09 11:14:19
问题 I am generating scripts in process method of TagHelper class as follows [TargetElement("MyTag")] public Class MYClass: TagHelper{ public override void Process(TagHelperContext context, TagHelperOutput output) { StringBuilder builder = new StringBuilder(); builder.Append("<script>"); builder.Append("//some javascript codes here); builder.Append("</script>"); output.Content.Append(builder.ToString()); } } Now it place the script very next to the tag element as its sibling. I need to place the

after adding @addTagHelper to the *.cshtml file. error 500 is shown

对着背影说爱祢 提交于 2020-01-06 20:19:35
问题 When I Use @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" in My .cshtml file it causes error 500. but it's work in another ViewComponent 回答1: which version? please give us more information. if you are using rc1-update1 use @addTagHelper *, Microsoft.AspNet.Mvc.TagHelpers 回答2: I had the same problem and couldn't figure out the exact cause. However, changing the "Microsoft.AspNet.Mvc.TagHelpers" depencency in my json file from "6.0.0-betaX" to "6.0.0-rc1-final" fixed the issue. Make sure to

Asp.Net MVC Core 1.0 - anchor tag helper with an empty area

旧时模样 提交于 2020-01-02 23:51:53
问题 I have an area called Admin, in one of my pages in this area, I want to navigate to the views that are located outside of my area, in fact it isn't in any area, with HTML helpers I could pass empty for that like so: @Html.ActionLink(item.ArticleTitle, "Details", new { id = item.ArticleId,title=item.ArticleTitle.Replace(' ', '-'), Area = "" }) But when using tag helper, passing empty doesn't work: <a asp-action="Details" asp-route-area="" asp-route-id="@item.ArticleId" asp-route-title="@item

ASP.NET Vnext Tag Helpers for Areas

北城以北 提交于 2020-01-02 00:32:40
问题 I may use <a href='/Area/Controller/action'> </a> in asp.net vnext but just want to know whether we can use tag helpers like <a asp-controller="ControllerName" asp-action="ActionName" asp-area="AreaName"> to redirect to the specific file in the area. Will any one guide me how to redirect to a file in area using tag helpers.? 回答1: Finally I got the answer from the following link which works well. <a asp-route-area="AreaName" asp-controller="ControllerName" asp-action="ActionName"> </a> github

Can I use a Tag Helper in a custom Tag Helper that returns html?

社会主义新天地 提交于 2019-12-30 03:46:04
问题 I recently ran into a situation where I would like to use a tag helper within a tag helper. I looked around and couldn't find anyone else trying to do this, am I using a poor convention or am I missing documentation? Ex. Tag Helper A outputs HTML that contains another tag helper. Ex. [HtmlTargetElement("tag-name")] public class RazorTagHelper : TagHelper { public override void Process(TagHelperContext context, TagHelperOutput output) { StringBuilder sb = new StringBuilder(); sb.Append("<a asp

How to add link parameter to asp tag helpers in ASP.NET Core MVC

ぐ巨炮叔叔 提交于 2019-12-29 03:11:32
问题 I have a lot of experience with ASP.NET MVC 1-5 . Now I learn ASP.NET Core MVC and have to pass a parameter to link in page. For example I have the following Action [HttpGet] public ActionResult GetProduct(string id) { ViewBag.CaseId = id; return View(); } How can I implement the link for this action using tag helpers? <a asp-controller="Product" asp-action="GetProduct">ProductName</a> 回答1: You can use the attribute prefix asp-route- to prefix your route variable names. Example: <a asp

Select-Tag Helper .NET Core to Controller

亡梦爱人 提交于 2019-12-25 01:27:30
问题 I have tried to submit tag-select with 'submit' button and it worked properly but how about without submit button ? I want to send the value of tag-select directly to controller every time it changes without javascript. Is that possible ? @model MyViewModel <form asp-controller="Home" asp-action="Create"> <select asp-for="EmployeeId" asp-items="@(new SelectList(Model.EmployeesList,"Id","FullName"))"> <option>Please select one</option> </select> </form> [HttpPost] public IActionResult Create

In a view component invoked as a tag helper, how can we access the inner HTML?

China☆狼群 提交于 2019-12-24 08:57:22
问题 In tag helpers, we can access the tags inner HTML. <!-- Index.cshtml --> <my-first> This is the original Inner HTML from the *.cshtml file. </my-first> // MyFirstTagHelper.cs > ProcessAsync var childContent = await output.GetChildContentAsync(); var innerHtml = childContent.GetContent(); If we invoke a view component as a tag helper, how can we access the inner HTML? <vc:my-first> This is the original Inner HTML from the *.cshtml file. </vc:my-first> // MyFirstViewComponent.cs > InvokeAsync()

Complex custom tag helper

拟墨画扇 提交于 2019-12-23 02:38:16
问题 Basically, I'm extending on a previously answered question (Updating related entities) so that it is a Custom Tag Helper. I want to send the custom tag helper a list of phones related to the user and generate a textbox for each. So, lets assume I have the following syntax: <user-phones phones="@Model.UserPhones" /> Here is the start I have for the Custom Tag Helper: public class UserPhonesTagHelper : TagHelper { private readonly IHtmlGenerator _htmlGenerator; private const string