1

I am rendering a Partialview as HTML string into a popover and I want to get an advice from you guys to ensure if my approach is correct

I have the following simple code

<button class="btn-link" data-toggle="popover" data-trigger="focus" data-html="true" data-placement="bottom" data-content="@Html.Partial("_Reminder").ToHtmlString()"><span class="badge badge-danger"><i class="fa fa-shield"></i> Unsecured</span></button>    

The partial view I am rendering is the following

    Reminder me : 
 <button class="btn btn-link glyphicon glyphicon-time" title="Tomorrow"></button> 
    <button class="btn btn-link glyphicon glyphicon-calendar" title="In 1 Week"></button>  
    <button class="btn btn-link glyphicon glyphicon-check" title="In 1 Month"></button> 

Result is pretty impressive but i am not sure if this is the right way to do that where i don't want a MODEL Popup and also i want to render this partial view right at the top of each item when clicked

Results are the following

enter image description here

But is there a better way to deal with this?

Also, I will have to Pass an ITEM ID to the partial view, therefore, i was thinking to use @{Html.RenderAction("ViewReminder", "Home", new { ID = 1 }); } instead of @Html.Partial("_Reminder").ToHtmlString()

Please advise

1 Answer 1

2

See the answer: Convert IHtmlContent/TagBuilder to string in C#

I implemented the Helper:

public static class HtmlContentExtension
{
    public static string GetString(this IHtmlContent content)
    {
        var writer = new System.IO.StringWriter();
        content.WriteTo(writer, HtmlEncoder.Default);
        return writer.ToString();
    }
}

And I used it in View:

string meta = Html.Partial("Meta", Model.Meta).GetString();
<span class="pop" title="Meta" data-html="true" data-content="@meta">@Model.Points</span>

PS: I used "HtmlEncoder.Default" because I'm using Core, if I use the ASP MVC default, use "new HtmlEncoder()".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.