简体   繁体   English

剃刀中的锚标签助手

[英]Anchor tag helper in razor

I´m trying to navigate to a details page outside of my current directory on a razor app.我正在尝试导航到剃刀应用程序上当前目录之外的详细信息页面。 If i use this static tag it works ok如果我使用这个静态标签它工作正常

<a href="/campdet/create/@Model.Camp.IdCamp">Details</a>

however if i try to use one of the tag helpers it produces an empty string in the href portion但是,如果我尝试使用其中一个标签助手,它会在 href 部分生成一个空字符串

<a asp-route="/campdet/create/1" class="btn btn-info"><i class="material-icons">zoom_in</i> </a>
<a asp-page="/campdet/create/1" class="btn btn-info"><i class="material-icons">zoom_in</i> </a><a href="/campdet/create/@Model.Camp.IdCamp">Details</a>

The destination page (campdet\\create) its constrained like this目标页面 (campdet\\create) 像这样受约束

@page "{id:int}"

I don´t have any special routing config on the startup.我在启动时没有任何特殊的路由配置。 What am i doing wrong ?我究竟做错了什么 ?

asp-page属性中指定页面名称,在asp-route-id属性中指定路由:EG:

 <a asp-page="/campdet/create" asp-route-id="@Model.Camp.IdCamp">zoom_in</a>

The anchor tag helper targets the HTML anchor () tag which is used to generate relative links from the values passed to various custom attributes.锚标记助手的目标是 HTML 锚 () 标记,该标记用于从传递给各种自定义属性的值生成相关链接。 It can also be used to generate absolute URLs to external resources.它还可以用于生成外部资源的绝对 URL。 The anchor tag helper's role is to generate an (href )attribute from the parameter values passed to its custom attributes.锚标记助手的作用是根据传递给其自定义属性的参数值生成 (href ) 属性。

Format :格式

@Html.ActionLink("Some link text", "MyAction", "MyController", protocol: null, hostName: null, fragment: "MyAnchor", routeValues: null, htmlAttributes: null) @Html.ActionLink("Some link text", "MyAction", "MyController", protocol: null, hostName: null, fragment: "MyAnchor", routeValues: null, htmlAttributes: null)

Example 1 (element on the 'Details' page with a link to click that will redirect to a specific section of the 'Edit' page, (eg, bottom of 'Edit' page)):示例 1 (“详细信息”页面上带有点击链接的元素,该链接将重定向到“编辑”页面的特定部分,(例如,“编辑”页面底部)):

<span style="float:right;">@Html.ActionLink(linkText: "Edit Notes", actionName: "Edit", controllerName: "Form", protocol: null, hostName: null, fragment: "anchor", routeValues: new { id = Model.FormId }, htmlAttributes: new { @class = "badge badge-pill badge-warning" })</span>    

Example 2 (element on the 'Edit' page with " name='anchor' " and " id = 'anchor' " in the topmost tag)示例 2 (“编辑”页面上的元素,在最顶层的标签中带有“name='anchor'”和“id = 'anchor'”)

<div name="anchor" id="anchor"class="form-group">
                                <div class="col-md-12">
                                    <span>@Html.Label("ReviewStatusNotes", "Notes (280 char max):", new { style = "font-weight:500" })</span>
                                    <span>@Html.TextAreaFor(model => model.ReviewStatusNotes, new { @class = "form-control", rows = "5" })</span>
                                    @Html.ValidationMessageFor(model => model.ReviewStatusNotes, "", new { @class = "text-danger" })
                                </div>
                            </div>    

OUTPUT:输出:

.../Form/Edit/8#anchor .../表格/编辑/8#anchor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM