floating point - Asp.net MVC decimal symbol issue -


i have asp.net mvc application particular view has model float property.

my server locale says , decimal symbol , works fine when edit model , enter instance 7,5 in text box , post server. default model binder able bind value expected seven , half.

but when display same value using <%= this.model.floatvalue %>, decimal symbol converted . means <%= %> ignores server locale settings.

so. how solve problem then? locale should used? server system locale says decimal symbol , or browser locale setting that's set en-gb, means . decimal symbol.

anyway. want work reliably.

some code:

my controller actions:

public actionresult settings() {     settings result = this.service.getactivesettings();     return view(result); }  [httppost] [handlemodelstateexception] public actionresult settings(settings data) {     if (!this.modelstate.isvalid)     {         throw new modelstateexception(); // custom exception isn't important here     }     settings result = this.service.savesettings(data);     return json(result); } 

the second 1 called asynchronously using $.ajax().

relevant part of partial view:

<%@ control language="c#" inherits="system.web.mvc.viewusercontrol<settings>" %> <div class="data">float value: <strong><%= this.model.floatvalue %></strong></data> <div class="data">integer value: <strong><%= this.model.intvalue %></strong></data> ... 

any model class:

/// <summary> /// represents application specific settings. /// </summary> public class settings {     /// <summary>     /// gets or sets integer value.     /// </summary>     /// <value>integer value.</value>     [required(errormessageresourcetype = typeof(resources.settings), errormessageresourcename = "quotarequired")]     [range(0, 365*24, errormessageresourcetype = typeof(resources.settings), errormessageresourcename = "quotarange")]     public int intvalue { get; set; }      [required(errormessageresourcetype = typeof(resources.settings), errormessageresourcename = "workdayrequired")]     [range(.5, 24.0, errormessageresourcetype = typeof(resources.settings), errormessageresourcename = "workdayrange")]     public float floatvalue { get; set; } } 

as may see, there's nothing unusual here. oh , btw: range validation on floatvalue doesn't work either.

did try disabling client based culture? can find in web.config, system.web section.

<globalization enableclientbasedculture="false"  /> 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -