[英]Format exception was unhandled by user code
@foreach (var result in Model)
{
////var num=Convert.ToInt32(x);
//int n=int.Parse(x);
//int n=Integer.parseInt(x);
if (Convert.ToInt64(@result.Difference) < 0)
{
<tr>
<td>@result.SalesIncentiveBuckets
</td>
<td>@result.CurrentMonth
</td>
<td>@result.SameMonthPrevYear
</td>
<td style="color:Red;">@result.Difference
</td>
<td>@result.BonusAmount
</td>
</tr>
}
else
{
<tr>
<td>@result.SalesIncentiveBuckets
</td>
<td>@result.CurrentMonth
</td>
<td>@result.SameMonthPrevYear
</td>
<td>@result.Difference
</td>
<td>@result.BonusAmount
</td>
</tr>
}
}
In my model difference is a string, and I want to convert it into integerI tried in all the ways I could, but it is showing this error: 在我的模型中,差异是一个字符串,我想将其转换为整数我已经尽我所能尝试了,但是它显示了这个错误:
input string not in a correct format
输入的字符串格式不正确
It's the commas in the string causing this exception, Try this 是导致此异常的字符串中的逗号 ,请尝试以下操作
int num = int.Parse(result.Difference, NumberStyles.AllowThousands);
You have to add System.Globalization
namespace to achieve this. 您必须添加
System.Globalization
命名空间才能实现此目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.