ToString("C") formatting fails in ASP.NET MVC Partial View in VB.NET 2013 -
this line
@model.currentprice.tostring("c") works in c# 2013, fails in vb.net invalidcast exception.
the currentprice property nullable decimal.
i've had fix:
@ctype(model.currentprice, model.currentprice.gettype()).tostring("c") any thought of why @model.currentprice.tostring("c") not work in vb.net 2013 , how prepare instead of doing above conversion?
thanks, jean
what expecting line of code produce if currentprice nothing? unless you're 100% sure have value, need explicitly handle both cases, e.g.
@if(model.currentprice.hasvalue, model.currentprice.value.tostring("c"), string.empty) you can replace string.empty else if want else when there's no value.
asp.net-mvc vb.net string-formatting
No comments:
Post a Comment