簡體   English   中英

輸入字符串的正確格式

[英]correct format for Input string

我有如下的幫助方法。

@helper DisplayTrendIndicator(double lastYear, double twoYearsAgo)
{
if (lastYear > twoYearsAgo)
{
  <img id="green" src="@VirtualPathUtility.ToAbsolute("~/images/up.png")" />
}
else
{
  <img id="red" src="@VirtualPathUtility.ToAbsolute("~/images/down.png")" />
}
}

當我嘗試在程序中調用該方法時,出現“輸入字符串格式不正確”的提示。 這就是我所說的上述助手

@Helpers.DisplayTrendIndicator(double.parse(lastYear.Content), double.parse(twoYearsAgo.Content))

注意:lastYear和twoYears是從API調用返回的變量。 我正在研究ASP.NET MVC項目C#。 如何防止出現此錯誤。

從API調用返回的變量lastYear和twoYears的值是什么?

嘗試使用Convert.ToDouble()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM