true instead of True (C#)

asp.net-mvc, asp.net-mvc-4, c#

Solution

As a boolean (`bool`), the values will always be "True" or "False". If you want to represent these differently when converted to a string, you can do the following in your view:

@Model.IsAdded.ToString().ToLower()

Problem

The goal Return `true` instead of `True` from Controller to View. The problem I'm storing into a variable a boolean that indicates whether a product exists or not in a shopping cart/summary. To achieve this, I'm doing the following: ``` [...] IsAdded = sessionStore.CheckExistanceOnSummary(product.productId) [...] ``` But, when I show the value of `IsAdded` on the View, the return is `True` or `False` — and JavaScript is expecting `true` or `false`. What I need is to send `true` or `false` instead of this way that C# is sending. What I've already tried I already tried to change the above's code fragment into this: ``` IsAdded = (sessionStore.CheckExistanceOnSummary(product.productId) ? "true" : "false") ``` But debugger returns me the following error: Error 5 Cannot implicitly convert type 'string' to 'bool' A few lines of code The implementation of `CheckExistanteOnSummary` is: ``` public bool CheckExistanceOnSummary(Nullable<int> productId) { List<Products> productsList = (List<Products>)Session[summarySessionIndex]; if (productsList.Where (product => product.id == (int)productId).FirstOrDefault() == null) return false; else return true; } ``` Duplicated? I read this topic, but didn't not help me.

Original source

Related problems