Search code examples
htmlasp.net-mvcasp.net-mvc-4razor

MVC - How to render a 'a href' link in a CSHTML on a HTML and PDF that's been stored in a database


I have an MVC app with CSHTML view

There are 2 question, that have text as "This is the website Google to search." The text is stored in DB and displayed on the cshtml page which will be rendered as HTML and PDF.

The issue is the link on the html and PDF is rendered as below

"This is the website <a href="https://google.com/">Google</a> to search."

as whole text

However I need it to be rendered as "This is the website Google to search." (where Google as hyperlink)

I am rendered questions as below - it is working fine for other question, but need to render the hyperlink correctly.

@foreach (var question in @Model.Questions)
        {
            
            <p>
                <div>@question.Description</div>
                <div style="padding-left:10px;">[email protected]</div>
            </p>
        }
        

Can you please help and advice for rendering the hyperlink correctly on HTML and PDF.


Solution

  • I resolved this by adding the Model value inside @Html.Raw()

    Eg : <div>@Html.Raw(@question.Question1)</div>
    

    Hope this would be helpful to someone :)