The scenario is I would like to write a hidden field with a guid value generated by the server.
Why does
<input type="hidden" id="sampleGuid" value="@{Guid.NewGuid().ToString()};" />
yield ‘value=””‘ while
@{
string token = Guid.NewGuid().ToString();
<input type="hidden" id="sampleGuid" value="@token" />
}
properly fill in ‘value’ with a guid?
You need parentheses instead of braces.
@{ ... }will execute ordinary statements, but won’t print anything.@(...)will print the value of an expression. (and will HTML-encode it)