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"]);
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
Post a Comment