value of weight which is of datatype float is not showing

gaurav
gaurav
Member
12 Points
1 Posts

 

if (weight > 1 && weight <= 1.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 3);
                sprice = amount.amount.ToString();
            }

the value sprice is 100.00 after debugging 

now i have stored that sprice in session 

 Session["price"] = sprice;

after thatt this session has been stored in viewdata 

 ViewData["amount"] = Session["price"];

but when i am trying to show viewdata in my view it is showing 00 

 @Html.Label(ViewData["amount"].ToString(), new { @class = "display", style="margin-left:40px;"})

 

Thanks in advance

Views: 9650
Total Answered: 2
Total Marked As Answer: 0
Posted On: 15-Jul-2015 23:34

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

Hi gaurav,

I think problem in showing in label

@Html.Label(ViewData["amount"].ToString(), new { @class = "display", style="margin-left:40px;"})

You need to give more left margin.

Please try to see value in browser by using inspect or view source. If value is showing 100.00 then increase the left margin some thing 100 else let me know.

 

 

Posted On: 15-Jul-2015 23:42
gaurav
gaurav
Member
12 Points
1 Posts
         
  public JsonResult GetPrice(float fweight, float flength, float fwidth, float fheight)
        {
           
            string sprice=string.Empty;
            Session["weight"] = fweight;
            Session["length"] = flength;
            Session["width"] = fwidth;
            Session["height"] = fheight;
            tblamount objamount = new tblamount();
            //float weight = (float)objamount.weight;
            float weight = fweight;
            if (weight > 0 && weight <= 0.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 1);
                sprice = amount.amount.ToString();
            }

            if (weight > 0.5 && weight <= 1)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 2);
                sprice = amount.amount.ToString();
            }
            if (weight > 1 && weight <= 1.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 3);
                sprice = amount.amount.ToString();
            }
            if (weight > 1.5 && weight <= 2)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 4);
                sprice = amount.amount.ToString();
            }
            if (weight > 2 && weight <= 2.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 5);
                sprice = amount.amount.ToString();
            }
            if (weight > 2.5 && weight <= 3)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 6);
                sprice = amount.amount.ToString();
            }
            if (weight >3 && weight <= 3.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 7);
                sprice = amount.amount.ToString();
            }
            if (weight > 3.5 && weight <= 4)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 8);
                sprice = amount.amount.ToString();
            }
            if (weight > 4 && weight <= 4.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 9);
                sprice = amount.amount.ToString();
            }
            if (weight > 4.5 && weight <=5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 10);
                sprice = amount.amount.ToString();
            }

            if (weight > 5 && weight <= 5.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 11);
                sprice = amount.amount.ToString();
            }

            if (weight > 5.5 && weight <= 6)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 12);
                sprice = amount.amount.ToString();
            }
            if (weight > 6 && weight <= 6.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 13);
                sprice = amount.amount.ToString();
            }
            if (weight > 6.5 && weight <= 7)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 14);
                sprice = amount.amount.ToString();
            }
            if (weight > 7 && weight <= 7.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 15);
                sprice = amount.amount.ToString();
            }
            if (weight > 7.5 && weight <= 8)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 16);
                sprice = amount.amount.ToString();
            }
            if (weight > 8 && weight <= 8.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 17);
                sprice = amount.amount.ToString();
            }
            if (weight > 8.5 && weight <= 9)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 18);
                sprice = amount.amount.ToString();
            }
            if (weight > 9 && weight <= 9.5)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 19);
                sprice = amount.amount.ToString();
            }
            if (weight > 9.5 && weight <= 10)
            {
                var amount = db.tblamounts.SingleOrDefault(x => x.id == 20);
                sprice = amount.amount.ToString();
            }
            Session["price"] = sprice;
            return Json(sprice,JsonRequestBehavior.AllowGet);
        }
Posted On: 16-Jul-2015 00:24
 Log In to Chat