I’m trying to learn Razor but have come up against a syntax problem. When I run the following code:
@if (searchTerm != ""){
<h2>Showing @ExamineManager.Instance.Search(searchTerm, true).Count() results for @searchTerm</h2>
<div class="search-results">
@foreach (var result in ExamineManager.Instance.Search(searchTerm, true)) {
if (result.Fields["nodeTypeAlias"] == 'File'){
<p>File</p>
}else{
<p>Not file</p>
}
}
</div>
}
this errors, saying “Too many characters in character literal”. The actual mechanism of the code works, it’s just a syntax problem with the way the conditionals are nested I think, but I’ve tried various combinations of @{} blocks and prepending @ to various lines but just can’t get it to work.
Can anyone see what I’m doing wrong?
Thanks!
That is because you’ve got comparison
In c#, you cannot write strings into single quotes like that. You should change it into