Nerf
Nerf

Reputation: 938

JavaScript function to format text

I have something like that in my ASP.NET MVC View page.

<li>Status: <span id="serviceStatus">formatServiceAvaibility(@service.Avaiable);</span></li>

service is stronly typed object. And function:

function formatServiceAvaibility(serviceStatus) {
    if (serviceStatus == true)
        return 'ON';
    return 'OFF';
}

Why this doesn't work while loading page? Result is: Status: formatServiceAvaibility(True);

How to make that?

Upvotes: 0

Views: 57

Answers (1)

Martin Staufcik
Martin Staufcik

Reputation: 9490

That may be because c# formats bool with a capital letter. Try to change the code to

formatServiceAvaibility(@(service.Avaiable ? "true" : "false"));

or

formatServiceAvaibility(@(service.Avaiable.ToString().ToLower()));

Upvotes: 2

Related Questions