I’m trying to figure this simple thing but I’m actually embarrassed to ask such a newbie question. Im so used to mvc2 and i jumped into my first mvc3 project some days ago. anyway the question is how can i add model value in a class name or id
<div class="remove-MODEL.ID">body...</div>
in mvc2 its simple
<div class="remove-<%= Model.Id %>">body...</div>
my current code and try is (WORKS)
<div class="remove-@Model.Id">body...</div>
i tried a string format instead (WORKS)
<div class="@string.format("{0}", Model.Id)">body...</div>
i really have no idea and like i said such a simple thing becomes the hardest 🙂
EDIT
It is really odd but my third and forth suggestion worked after a couple of tries
Erik Philips answer got info about this issue.
This is one of the minor limitations of the Razor engine. The problem lies in the engines ability to determine if the @ is razor syntax or just regular html text. This example can occur frequently when the razor output is
<prefixvalue>@<model>.<value>because that is similar to the email expression<name>@<emailprovider>.com. You can force the engine to assume razor syntax by surrounding the expression in parentheses (e.g.@(model.id)).