在我看来,我有这种情况:
@if (User.Identity.Name == "abc")
{
... do this!
}
如何在 View 中(在 MVC 中)拆分此字符串“User.Identity.Name”,以便创建新条件,如下所示:
string last = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('.') + 1);
if (last == "this")
{
... do this!
}
谢谢。
最佳答案
你可以这样做:
@{
var temp= User.Identity.Name.Split('.');
if (temp[temp.Count() - 1] == "this")
{
}
}
或者如果 "." 在该字符串中只有一次,那么您可以像这样进行硬编码:
@{
var temp= User.Identity.Name.Split('.');
if (temp[1] == "this")
{
}
}
关于asp.net-mvc - 如何在MVC的 View 中拆分字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24114849/