I have a razor string
@postername.Substring(0, @postername.IndexOf("@"))
If the username has email I get the username before @ sign but if the username doesn't have email I want to have that whole word, how to do ?
if(@postername.Contains("@")){
@postername.Substring(0, @postername.IndexOf("@"))
}else{
@postername
}
but didn't work, pls help
If you must do this at View level, build the logic into a variable first:
@{
string posternameShort = postername;
if(postername.Contains("@")){
posternameShort = postername.Substring(0, postername.IndexOf("@"))
}
}
Then call the new variable:
@posternameShort
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With