asp.net mvc - Javascript object to C# object does not correctly convert double -


i'm trying send model created using javascript (because created manually user) mvc controller.

the model quite complex , 1 class uses double? type variable. works fine int numbers when use "0.5" value set null.

what reason why double value fail , can it?

some code:

var serie = {};  serie.name = $(elem).children("#name").val();  serie.unitmeasurement = $(elem).children("#unitmeasurement").val();  serie.thresholdred = $(elem).children("#redthreshold").val();  serie.thresholdyellow = $(elem).children("#yellowthreshold").val();   public class serie         {             public string name { get; set; }             public string unitmeasurement { get; set; }             public double? thresholdred { get; set; }             public double? thresholdyellow { get; set; }         } 

you can use class like-

public class serie {     public string name { get; set; }     public string unitmeasurement { get; set; }     public string thresholdred { get; set; }     public string thresholdyellow { get; set; } } 

and while using these varriables can convert them like-

double? d = convert.todouble(thresholdred); 

or can use double.tryparse like-

double d; bool result = double.tryparse(str, out dbl); // `result` status of tried parsing (true or false) 

edited :(

in order avoid confusion culture, encode parameters before sending like-

var serie = {}; serie.name = escape($(elem).children("#name").val()); serie.unitmeasurement = escape($(elem).children("#unitmeasurement").val()); serie.thresholdred = escape($(elem).children("#redthreshold").val()); serie.thresholdyellow = escape($(elem).children("#yellowthreshold").val()); 

while using them on server, decore them first-

double? d = convert.todouble(httputility.htmldecode(thresholdred)); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -