asp.net mvc - Input string was not in a correct format MVC -


i want convert session["price"] decimal , convert session["count"] integer

        doc.price = convert.todecimal(session["price"]);         doc.count = convert.toint16(session["count"]);  

i error enter image description here

var stringvalue = session["price"].tostring(); if(!string.isnullorempty(stringvalue)) {     try {        doc.price = convert.todecimal(stringvalue);     }     catch(formatexecption ex) {         // should not have gotten here because frontend should gaurd against input values not number anyway        throw new validationexecption("price not number"); } 

this issue have here whole not practicing defensive coding. go , learn defensive coding improve quality of code


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -