title: ASP.Net MVC3 Modify culture for date and decimal through or not Visual Studio?
body: <p>I'm working on an MVC3 application with Razor. I'm having troubles using Dates and doubles on my views. Both my Windows and Visual Studio are English, but I want to customize the culture of my project in "it-IT". 
  I found several articles how to manage different cultures, through the JQuery Validation Plugin or directly setting the culture on the page, but I'm a lot confused!!!
  The format I want use for dates is "DD/MM/YYYY", while for double is 1.234,32. So, </p>
  
  <ul>
  <li>How can I tell to Visual Studio how to use these formats (I checked on the Visual Studio's settings and there is only English)?</li>
  <li>MVC injects code to validate my fields, how to change it?</li>
  <li>What is the best approach?</li>
  </ul>
  
  <p>Obviously any suggest would be appreciated. 
  I post the code of my project:</p>
  
  <p>Offerta.cs</p>
  
  <pre><code>[MetadataType(typeof(Offerta_Validation))]
  public partial class Offerta
  {
  }
  
  public class Offerta_Validation
  {
      [HiddenInput(DisplayValue = false)]
      public int IDOfferta { get; set; }
  
      [StringLength(300, ErrorMessage = "Campo troppo lungo")]
      [Required(ErrorMessage = "Campo obbligatorio")]
      public string Titolo { get; set; }
  
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:N2}")]
      [Required(ErrorMessage = "Campo obbligatorio")]
      [Price(MinPrice=0.01)]
      public decimal PrezzoIniziale { get; set; }
  
      [Required(ErrorMessage = "Campo obbligatorio")]
      [Integer]
      public int BuoniScontiMinimo { get; set; }
  
  
      public string Sconto { get; set; }
  
      [Date]
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
      public System.DateTime DataAttivazione { get; set; }
  
      [DataType(DataType.MultilineText)]
      [AllowHtml]
      public string Sintesi { get; set; }
  
      [DataType(DataType.MultilineText)]
      [Required(ErrorMessage = "Inserire le condizioni")]
      [AllowHtml]
      public string Condizioni { get; set; }
  
      [DataType(DataType.MultilineText)]
      [Required(ErrorMessage = "Inserire la descrizione")]
      [AllowHtml]
      public string Descrizione { get; set; }
  }
  </code></pre>
  
  <p>The field "PrezzoIniziale" is a double on DB. The annotation [Price] derive by this post <a href="http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx">http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx</a>. This is my view:</p>
  
  <pre><code>@model ManagerEmail.Models.OffertaFormViewModel
  
  &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;
  &lt;script type="text/javascript" src="@Url.Content("~/Scripts/jquery.global.js")"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="@Url.Content("~/Scripts/jquery.glob.it-IT.js")"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="@Url.Content("~/Scripts/tiny_mce/tiny_mce.js")"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      tinyMCE.init({
          // General options
          mode: "textareas",
          theme: "advanced",
          plugins: "style,searchreplace,paste",
  
          theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
          theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,forecolor,backcolor,|,styleprops",
          theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap,|,link,unlink,anchor,image,cleanup,help,code",
          theme_advanced_toolbar_location: "top",
          theme_advanced_toolbar_align: "left",
          theme_advanced_statusbar_location : "bottom",
  
          // Skin options
          skin : "o2k7",
          skin_variant : "silver",
  
          width: "510",
          height: "300",
          object_resizing: false,
  
      });
  &lt;/script&gt;
  
  @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editForm" })){
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;&lt;/legend&gt;
  
          &lt;ul&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.Titolo)
                  @Html.EditorFor(model =&gt; model.Offerta.Titolo) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.Titolo)
              &lt;/li&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.PrezzoIniziale, "Prezzo iniziale")        
                  @Html.EditorFor(model =&gt; model.Offerta.PrezzoIniziale) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.PrezzoIniziale)
              &lt;/li&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.BuoniScontiMinimo, "Minimo Buoni")
                  @Html.EditorFor(model =&gt; model.Offerta.BuoniScontiMinimo) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.BuoniScontiMinimo)
              &lt;/li&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.Sconto)
                  @Html.EditorFor(model =&gt; model.Offerta.Sconto) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.Sconto)
              &lt;/li&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.DataAttivazione, "Data Attivazione")
                  @Html.EditorFor(model =&gt; model.Offerta.DataAttivazione) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.DataAttivazione)
              &lt;/li&gt;
              &lt;li&gt;
                  &lt;label for="ddlAffiliato"&gt;Affiliato&lt;/label&gt;
                  @Html.DropDownListFor(model =&gt; model.Offerta.Affiliato.IDAffiliato, new SelectList(Model.Affiliati, "IDAffiliato", "RagioneSociale"), new { @id = "ddlAffiliato"} )
              &lt;/li&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.Condizioni)  &lt;br /&gt;           
                  @Html.TextAreaFor(model =&gt; model.Offerta.Condizioni) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.Condizioni, "", new { style = "top: -30px; left: 210px" })
              &lt;/li&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.Sintesi)  &lt;br /&gt;           
                  @Html.TextAreaFor(model =&gt; model.Offerta.Sintesi) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.Sintesi)
              &lt;/li&gt;
              &lt;li&gt;
                  @Html.LabelFor(model =&gt; model.Offerta.Descrizione)  &lt;br /&gt;           
                  @Html.TextAreaFor(model =&gt; model.Offerta.Descrizione) &lt;br /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Offerta.Descrizione, "", new { style = "top: -30px; left: 210px" })
              &lt;/li&gt;
          &lt;/ul&gt;
          @Html.HiddenFor(model =&gt; model.Provincia.IDProvincia)                 
      &lt;/fieldset&gt;
      &lt;p&gt;  
          @Html.AntiForgeryToken()
          &lt;input type="submit" value="Salva" id="submitButton"/&gt;
      &lt;/p&gt;
  }
  
  &lt;script type="text/javascript"&gt;
  
      $("#Offerta_PrezzoIniziale").removeAttr("data-val-number"); //I forced this because MVC adds the data-val-number, so it doesn't accept double values :(
  
      $(function () {
          jQuery.global.preferCulture("it-IT");        
      });
  
      $("#submitButton").click(function () {
          tinyMCE.triggerSave();
      });
  
  
  &lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(function () {
          jQuery.validator.addMethod("price", function (value, element, params) {
              if (this.optional(element)) {
                  return true;
              }
  
              if (value &gt; params.min) {
                  var cents = value - Math.floor(value);
                  if (cents &gt;= 0.99 &amp;&amp; cents &lt; 0.995) {
                      return true;
                  }
              }
  
              return false;
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>And this is my FormViewModel</p>
  
  <pre><code>public class OffertaFormViewModel
      {
          public Provincia Provincia { get; set; }
          public Offerta Offerta { get; set; }
          public IEnumerable&lt;Affiliato&gt; Affiliati { get; set; }
      }
  </code></pre>
  
  <p>Thanks!</p>