Using .net core, how can i show the html content coming from database on view

16,406

Got the solution. i was missing the model. I declared the model and then passed that model to the view and then used @Html.Raw(@Model.Property) at view to render the HTML.

Thanks @adem caglin.

Share:
16,406

Related videos on Youtube

Salman Lone
Author by

Salman Lone

By day: I am doing a job as a Senior Software Engineer. By Night: I give time to myself and my family. For Fun: I play football and watch movies. I believe in team work and innovations. I am goal oriented and I love to learn new things.

Updated on June 04, 2022

Comments

  • Salman Lone
    Salman Lone almost 2 years

    I have the business login written in Application_BeginRequest method of Global.asax file where i get an html content from database and set the content at view using literal control.

    Now i am migrating the project into .net core where i want the same thing to do as mentioned above. I have got the html content in the code using middleware but now i am trying to show the content on view but unable to do so.

    Following is my model

    @model string
    <div id="content">@Model</div>
    

    and i am returning

    return View(html);
    

    as a string.

    My question is, i want to know the steps that how can i show the html content coming from database on view using .net core.

    • adem caglin
      adem caglin over 7 years
      You can use @Html.Raw(Model) to render html string.
  • ThomasRones
    ThomasRones almost 5 years
    Not sure about 1.x, but in .NET Core 2.0 you don't need the second @ (It works both ways though)