I am trying to split
the string
based on ;
and store it in array of string
in MVC Razor view
and I tried it as below:
@{
string[] replies = !string.IsNullOrEmpty(messages.MessageReply) ? messages.MessageReply.Split(';') : new string []{};
}
But whenever I write this it will treat last }
of the string[] replies
as its main closing bracket instead of the one below. How can I avoid this or how would I be declaring such sort of variables in razor view?
Pust conditional expression into brackets:
string[] replies = (!string.IsNullOrEmpty(messages.MessageReply) ? messages.MessageReply.Split(';') : new string []{ });
Or... just get rid of brackets:
string[] replies = !string.IsNullOrEmpty(messages.MessageReply) ? messages.MessageReply.Split(';') : new string [0];
It should help
I guess you could use: string[0]
instead of string[]{}
:
@{
string[] replies = !string.IsNullOrEmpty(messages.MessageReply) ? messages.MessageReply.Split(';') : new string [0];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.