[英]ASP.NET Razor tag helper inside text string
In my razor page view I'm populating a model to pass to a partial, like this:在我的 razor 页面视图中,我正在填充一个模型以传递给部分,如下所示:
Razor Page剃刀页
@{
if (Model.Success)
{
Model.AlertMessage = new AlertMessage()
{
Title = "Email Confirmed",
Description = "Your email has been confirmed, you can now <a href=\"/login\">login</a> to your account."
};
}
else
{
Model.AlertMessage = new AlertMessage()
{
Title = "Confirmation Failed",
Description = "Your email could not be confirmed, please <a href=\"/confirmemail\">try again</a>."
};
}
}
<div class="row">
<div class="col-md-8 offset-md-2">
<partial name="_Partials/Alerts/_AlertMessage", model="Model.AlertMessage"/>
</div>
Partial View局部视图
@model AlertMessage
<div class="alert">
<div class="row">
<div class="col-auto align-self-center alert-icon">
</div>
<div class="col">
<span class="alert-title">@Model.Title</span>
<p class="alert-content">@Html.Raw(@Model.Description)</p>
</div>
</div>
The above is working, but I'm wondering if it is possible to use a razor tag helper inside the text string?以上是有效的,但我想知道是否可以在文本字符串中使用剃刀标签助手? To somehow replace the hard coded anchor tag
<a href=\\"/login\\">login</a>
with a tag helper <a asp-page="/Login">
and have it render the HTML properly?以某种方式用标签助手
<a asp-page="/Login">
替换硬编码的锚标签<a href=\\"/login\\">login</a>
并让它正确呈现 HTML?
if (Model.Success)
{
Model.AlertMessage = new AlertMessage()
{
Title = "Email Confirmed",
Description = "Your email has been confirmed, you can now" + @Html.ActionLink("Login", "Login") + "to your account."
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.