0

I am trying to add 2 variable in my razor view. I have assigned some fixed values to Value1 and Value2 in web.config file. But instead of adding values its concatenating (Instead of add 10+10=20 I am getting 1010) with below code.

@model Myproject.Models.Cost
@{
   ViewBag.Title = "About";
   var addvalue1 = ConfigurationManager.AppSettings["Value1"];
   var addvalue2 = ConfigurationManager.AppSettings["Value2"];

   var total = addvalue1 + addvalue2;
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
@using (Html.BeginForm())
{
   <p>Your total is : @total</p>

}
jina
  • 115
  • 11
  • Possible duplicate of [How can I convert String to Int?](https://stackoverflow.com/questions/1019793/how-can-i-convert-string-to-int) – haldo Apr 09 '19 at 17:19
  • 1
    Possible duplicate of [How to add two strings that are numbers?](https://stackoverflow.com/questions/31711326/how-to-add-two-strings-that-are-numbers) – gunr2171 Apr 09 '19 at 17:19
  • 3
    The values are being returned as strings. You just need to convert to int: `Convert.ToInt32()` or `int.Parse()` – haldo Apr 09 '19 at 17:22

0 Answers0