Robert Smith
Robert Smith

Reputation: 634

How to trim <text> from MVC cshtml

Using MVC, I have the following if statement in the javascript portion of my CSHTML:

var url = '@if (@HttpContext.Current.Session["id"].ToString() == "1")
{
    <text>Testing one two three</text>
}
else
{
    @Url.Action("GetCustomer", "Customer")

}';

If I go into the ELSE portion, everything is fine and the following is produced:

var url = '/Customer/GetCustomer';

However, if I go into the IF portion, I am getting too much white space:

var url = '                  
Testing one two three  ';

My question is, how can I trim that extra white space out and show as follows:

var url = 'Testing one two three';

Thank You before hand.

Thanks to Ciubotariu Florin here is the answer:

var url = '@(HttpContext.Current.Session["id"].ToString() == "1" ? "Testing one two three" : @Url.Action("GetCustomer", "Customer") )';

Upvotes: 0

Views: 426

Answers (1)

Remove the <text></text> tags:

var url = '@(HttpContext.Current.Session["id"].ToString() == "1" ? "Testing one two three" : @Url.Action("GetCustomer", "Customer") )';

Upvotes: 1

Related Questions