Reputation: 403
I have a variable itotqty in my .cshtml file, which is declared as follows:
var itotqty = 0;
itotqty = itotqty + item.TOT_QTY;
what I want is, I need to show it's value inside <td></td>
tag.
I have tried below combinations:
<td style="text-align: center"><b> +itotqty.ToString()+ </b></td>
<td style="text-align: center"><b>' + itotqty.ToString() + '</b></td>
<td style="text-align: center"><b>"' + itotqty.ToString() + '"</b></td>
But showing that variable instead of its value while running the page.
Upvotes: 1
Views: 2853
Reputation: 746
You have to use Razor syntax. More about Razor C# Syntax read here:http://www.w3schools.com/aspnet/razor_syntax.asp
Your solution:
@{
var itotqty = 0;
itotqty = itotqty + item.TOT_QTY;
}
then
<td style="text-align: center"><b>' + @itotqty.ToString() + '</b></td>
note, you have to use "@" when want to acces to variable you declared in c#
Upvotes: 0
Reputation: 11
You need to present the variable in the <td></td>
tag this way.
<td style="text-align: center"><b> @(itotqty) </b></td>
Upvotes: 1
Reputation: 635
convert Var to string after,
private string stritotqty;
stritotqty = Convert.ToString(itotqty);
public string itotqty { get { return stritotqty ; } }
<td style="text-align: center"><b> <%=itotqty%></div> </b></td>
same as others,
Upvotes: 0
Reputation: 53958
First we have to include both the declaration of itotqty
and the expression in a @{ }
block
@{
var itotqty = 0;
itotqty = itotqty + item.TOT_QTY;
}
Then you can refer to this variable as @itotqty
.
<td style="text-align: center"><b> [email protected]()+ </b></td>
Upvotes: 3