Take the 2-minute tour ×

I am trying to format the output of a query in a WebMatrix 2 CSHTML file. This is the code I am using:

@foreach(var row in db.Query(selectQueryString))
   @row.Firstname; + " " + @row.lastname; + " " + @row.Entry;

I am getting this error: "CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement"

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The first issue is that the semicolons could be confusing to Razor, and they are only confusing matters. So change the line in the brackets to

<text>@row.Firstname @row.lastname @row.Entry</text>

And see if that works. The < text > tags tells Razor to output this directly as HTML and not use it as code. You don't need the + " " because once you're putting out HTML, the spaces come automatically.

share|improve this answer
Great! That works. Thank you! –  zucchini Oct 17 '12 at 18:53
add comment

Your Answer


