2
Using ASP.Net MVC and Angularjs I tested the contents of a view thus:
$scope.estado.ldRedeBasica = @(Model.ldRedeBasica == null ? "[]" : Html.Raw(Model.ldRedeBasica));
Only it returned the following error:
Compiler Error Message: CS0173: The conditional expression type cannot be determined because there is no implicit conversion between 'string' and 'System.Web.Ihtmlstring'
The interesting thing is that in another part of the code works:
$scope.ViewBag.Impostos = @(ViewBag.Impostos == null ? "[]" : Html.Raw(ViewBag.Impostos));
How to get around this problem?
Thank you for the answer! Really did not return the original error. Now it is returning Uncaught Syntaxerror: Unexpected token ; in the console the code is so:
$scope.estado.ldRedeBasica = ;
.– Jothaz
What kind is
Model.ldRedeBasica
?– Miguel Angelo
If it is an array or list, you must serialize the object to JSON before using
Html.Raw
in it.– Miguel Angelo
I resolved so:
$scope.estado.ldRedeBasica = @(String.IsNullOrEmpty(Model.ldRedeBasica) ? Html.Raw("[]") : Html.Raw(Model.ldRedeBasica));
. Thanks for the help.– Jothaz
From what I said, you can tell the guy’s a string. Use
String.IsNullOrWhiteSpace
instead, to rule out the possibility of white spaces.– Miguel Angelo
It was barely String even! I’ll make the change. Thanks again!
– Jothaz