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.
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.
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.
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With