2
votes

In my razor page view I'm populating a model to pass to a partial, like this:

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?

1
I would extend the model with a new filed Link and pass it into Partial View. - Basil Kosovan

1 Answers

1
votes
    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."
    };
}