How to split string in View in MVC?

geekforfreek

In my View I have this condition:

@if (User.Identity.Name == "abc")
{
   ... do this!
}

How can I split this string "User.Identity.Name" in View (in MVC) so I can create new condition, something like this:

string last = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('.') + 1);
if (last == "this")
{
   ... do this!
}

thanks.

Ehsan Sajjad

you can do it like this:

@{

    var temp= User.Identity.Name.Split('.');

    if (temp[temp.Count() - 1] == "this")
    {

    }

}

or if "." will be only one time in that string then you can hardcode like this:

@{

    var temp= User.Identity.Name.Split('.');

        if (temp[1] == "this")
        {

        }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related