0

I have a helper method as follows.

@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")" />
}
}

When I try to invoke the method in my program, I get an "Input string was not in a correct format". This is how I call the above helper

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

Note: lastYear and twoYears ago are variables returned from an API call. I'm working on an ASP.NET MVC Project C#. How do I prevent this error from popping up.

5
  • Couldn't this be in your model to avoid confusing use of @ in razor? You could have it in your model and call it like @Model.DisplayTrendIndicator Commented Dec 13, 2016 at 12:56
  • The problem is with one of the double.Parse calls and the string that you are passing is not in the format of a double. Commented Dec 13, 2016 at 13:00
  • What are the values of: lastYear.Content and twoYearsAgo.Content? Commented Dec 13, 2016 at 13:13
  • Check it "lastYear.Content" and "twoYearsAgo.Content". Commented Dec 13, 2016 at 13:17
  • Lastyear.Content and twoyearsago.Content are strings Commented Dec 13, 2016 at 13:36

1 Answer 1

1

what are the values of lastYear and twoYears ago are variables returned from an API call.those are string??

try with Convert.ToDouble()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.