Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC 3 RC 2 client side validation with globalization
    primarykey
    data
    text
    <p>My goal is to validate a user input on the client-side, depending on the users' culture.</p> <p>I have a primitive data-model with the following structure:</p> <pre><code>public class User { public int UserId { get; set; } [Required] [StringLength(20,MinimumLength=3)] public string Name { get; set; } [Required] public double Height { get; set; } } </code></pre> <p>Furthermore, I want to have client-side validation enabled, checking if it is a valid number. Therefore, I've added the following lines in the <code>&lt;head&gt;</code> section of my _Layout.cshtml.</p> <pre><code>&lt;script src="@Url.Content("~/Scripts/jQuery-1.4.2.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>Since I want to have the ability to validate the input in another language formats (in this particular context it's German with the decimal number format of <code>0,75</code> whereas in the US it would be <code>0.75</code>), I've added the following lines (<a href="http://weblogs.asp.net/scottgu/archive/2010/06/10/jquery-globalization-plugin-from-microsoft.aspx" rel="nofollow">jQuery Globalization PlugIn</a>) AFTER the previously mentioned <code>jquery.validate.min.js</code> and <code>jquery.validate.unobtrusive.min.js</code>.</p> <pre><code>&lt;script src="@Url.Content("~/Scripts/jquery.glob.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/globinfo/jquery.glob.de-de.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $.culture = jQuery.cultures['de-DE']; $.preferCulture($.culture.name); }); &lt;/script&gt; </code></pre> <p>In addition, I've added the following line to the <code>web.config</code> in the <code>system.web</code> section just to make sure that the German culture is always selected:</p> <pre><code>&lt;globalization culture="de-DE" uiCulture="de-DE" /&gt; </code></pre> <p>Now I am experiencing the following behavior:</p> <ul> <li>If I type in <code>0,1</code> (note the German 'spelling') in the textbox for the value of "Height", the validation error message <code>The field Height must be a number</code> appears and I'm not able to submit the form.</li> <li>If I type in <code>0.1</code> (English 'spelling'), I can submit the form but the server-side validation returns the following validation error message <code>The value '0.1' is not valid for Height.</code></li> </ul> <p>So now I am in some kind of dead lock where I can't get out.</p> <p>Again, my goal is to validate the decimal number input on the client AND server side, based on the users' culture (in this case it's forced to be German). What am I doing wrong?</p> <p>Any help is highly appreciated! Thank you in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload