I trying to convert HTML code from database to my page.
@foreach (DataRow Row in DT.Rows)
{
<p>@Row.ItemArray[1]</p>
<span ng-bind-html="mydata"></span>
<hr />
<script type="text/javascript">
var app = angular.module('magnos', ['ngSanitize']);
app.controller('mycont', function ($scope) {
$scope.mydata = '@Row.ItemArray[2]';
});
</script>
}
But the @Row.ItemArray[2]
is always return string, not HTML like this
<h1>Magnos</h1>
I want the HTML code to write as HTML code in my page, so the Magnos header show as header.
Thank you all I have found the solution, Heres the Solution:-
@foreach (DataRow Row in DT.Rows)
{
<h2>@Row.ItemArray[1]</h2>
<br />
<span ng-bind-html="get_pre('@Row.ItemArray[2]');"></span>
<hr />
<script type="text/javascript">
var app = angular.module('magnos', []);
app.controller('mycont', function ($scope, $sce) {
$scope.get_pre = function (x) {
return $sce.trustAsHtml(x);
};
});
</script>
}