Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 691
Salman Lone Avatar asked Aug 15 '16 08:08

Salman Lone


People also ask

What is ViewData in. net core?

ViewData is a ViewDataDictionary object accessed through string keys. String data can be stored and used directly without the need for a cast, but you must cast other ViewData object values to specific types when you extract them.

How to create View in dotnet core?

Control-click on the Views folder, and then Add > New Folder and name the folder HelloWorld. Control-click on the Views/HelloWorld folder, and then Add > New File. In the New File dialog: Select ASP.NET Core in the left pane.

What is Razor View in ASP net core?

A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup.

What is a view in ASP NET Core?

A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup.

How to display HTML content (data) from model in view in MVC?

Here Mudassar Ahmed Khan has explained with an example, how to display HTML content (data) from Model in View in ASP.Net MVC Razor. The HTML content (data) will be displayed using Html.Raw Helper method in ASP.Net MVC Razor.

How to display HTML content (data) in razor?

The HTML content (data) will be displayed using Html.Raw Helper method in ASP.Net MVC Razor. Please refer the following article for complete information on how to configure Bundles in ASP.Net MVC project.

What is a view in MVC?

A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are.cshtml files that use the C# programming language in Razor markup. Usually, view files are grouped into folders named for each of the app's controllers.


1 Answers

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.

like image 92
Salman Lone Avatar answered Sep 29 '22 15:09

Salman Lone