I am using MS WebMatrix to create a dynamic CSHTML page from data obtained from a database. I am using the razor syntax.
I have data being returned to my CSHTML page, but it has trailing digits etc. For example I want to format “123.4568” into “$123.46”
How do I get the result to display in the format I need? I also want to change text colour when a target is reached, etc.
You can set the format of values in a WebGrid using the format optional argument of the column constructor.
You could try something like this, where the color of Invoices is red if value > 50 or blue if not
but I see no reason to use WebGrids in your situation.
The WebGrid helper renders data from a database with support for paging and sorting, but your query returns only one value and you don’t need either of them.
Edited
A better solution is to query the table with the QueryValue method, which returns a single scalar value, and display the value without the WebGrid.
In the following an example for the only Invoice