I am trying to create google authorship for multiple authors of my site. I created basic syntax but it triggers error CS0151: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
@switch(Model.redaktor){ case "Adam": "<p>Adam Smith</p>"; break; case "John": "<p>John Reed</p>"; break; case "Ian": "<p>Ian Kowalski</p>"; break; default: "<p>Unknown author</p>"; break; }
Any ideas where the problem is? Kind regards, Pawel
I think now the problem is your quotes around the <p> tags. You don't need them and I think razor is interpretted them as code. Just to check have tested this in Razor and works OK...
dynamic x = "abc";
switch ((string)x)
{
case "abc":
<p>Hello</p>
break;
}
switch statement in Razor
Hello Guys!
I am trying to create google authorship for multiple authors of my site. I created basic syntax but it triggers error CS0151: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
@switch(Model.redaktor){
case "Adam":
"<p>Adam Smith</p>";
break;
case "John":
"<p>John Reed</p>";
break;
case "Ian":
"<p>Ian Kowalski</p>";
break;
default:
"<p>Unknown author</p>";
break;
}
Any ideas where the problem is? Kind regards, Pawel
Your property will be a dynamic, so you should be OK if you cast it to a string. I.e.
Thanks a lot Andy, but know I get: error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
I think now the problem is your quotes around the <p> tags. You don't need them and I think razor is interpretted them as code. Just to check have tested this in Razor and works OK...
is working on a reply...