Because split of a string does not return the string? returns System.net

0

I have variables of session[] created in my application which I must occupy in the view to show that information that has stored in memory. The question is, how can I read that session [] 'in the view but only a part of the text they contain? Example:

The following created [] 'sings:

Session["varUno"] = "Texto uno";
Session["varDos"] = "Texto dos";
Session["varTres"] = "Texto tres";

I was trying to read them this way:

@Session["varUno"].ToString().Split(' ');

To make it look like this: Text (without text one) but it returns something from System.Net ....

The data comes like this, so they do not tell me and if you better leave only the word Text to create the Session ...

    
asked by vcasas 15.05.2018 в 22:11
source

1 answer

2

SOLVED

The solution was to add a'.First () 'at the end of the call to retrieve the session .

@Session["varUno"].ToString().Split(' ').First();

"it turns out that split returns an array of strings, so I gave it back what you put up, because it had an array and when trying to transform it into string you saw only the name of the class (which is what I returned by default) the property tostring ()). Then, when doing first, you are applying linq to return the first value of that array, which is what you want "

I hope it can serve someone else. =)

    
answered by 15.05.2018 / 22:25
source