2014-09-19 58 views
0

我有数据库的休耕表,我使用的Microsoft SQL Server 2008 R2,这是我的表:您输入的值不适用于这个领域

enter image description here

我实现了基本的CRUD与实体框架功能在ASP.NET MVC应用程序(见http://code.msdn.microsoft.com/MVC5-Demo-with-Entity-c6bc81df

但是,当我执行这个代码,我试图值传递给float类型的列发生这种情况:

enter image description here

注意到这些列是浮动的。

为什么会发生这种情况?

这是我创建视图

@model FillDataTest.Models.Type 

@{ 
    ViewBag.Title = "Create"; 
} 

<h2>Create</h2> 

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> 
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> 

@using (Html.BeginForm()) { 
    @Html.ValidationSummary(true) 
    <fieldset> 
     <legend>Type</legend> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.ArtistName) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.ArtistName) 
      @Html.ValidationMessageFor(model => model.ArtistName) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.ArtistCode) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.ArtistCode) 
      @Html.ValidationMessageFor(model => model.ArtistCode) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.UrsiName) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.UrsiName) 
      @Html.ValidationMessageFor(model => model.UrsiName) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Factor) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Factor) 
      @Html.ValidationMessageFor(model => model.Factor) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Unit) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Unit) 
      @Html.ValidationMessageFor(model => model.Unit) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.UAG23ref) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.UAG23ref) 
      @Html.ValidationMessageFor(model => model.UAG23ref) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Group) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Group) 
      @Html.ValidationMessageFor(model => model.Group) 
     </div> 

     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 
} 

<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 

,并通过项目项创建一个ADO.NET实体数据模型

[EdmEntityTypeAttribute(NamespaceName="IonoDBModel", Name="Type")] 
    [Serializable()] 
    [DataContractAttribute(IsReference=true)] 
    public partial class Type : EntityObject 
    { 
#region Método de generador 
. 
. 
. 
#enregion 
    #region Propiedades primitivas 
. 
. 
. 
    /// <summary> 
     /// No hay documentación de metadatos disponible. 
     /// </summary> 
     [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
     [DataMemberAttribute()] 
     public global::System.Double Factor 
     { 
      get 
      { 
       return _Factor; 
      } 
      set 
      { 
       OnFactorChanging(value); 
       ReportPropertyChanging("Factor"); 
       _Factor = StructuralObject.SetValidValue(value); 
       ReportPropertyChanged("Factor"); 
       OnFactorChanged(); 
      } 
     } 
     private global::System.Double _Factor; 
     partial void OnFactorChanging(global::System.Double value); 
     partial void OnFactorChanged(); 

     /// <summary> 
     /// No hay documentación de metadatos disponible. 
     /// </summary> 
     [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] 
     [DataMemberAttribute()] 
     public global::System.String Unit 
     { 
      get 
      { 
       return _Unit; 
      } 
      set 
      { 
       OnUnitChanging(value); 
       ReportPropertyChanging("Unit"); 
       _Unit = StructuralObject.SetValidValue(value, true); 
       ReportPropertyChanged("Unit"); 
       OnUnitChanged(); 
      } 
     } 
     private global::System.String _Unit; 
     partial void OnUnitChanging(global::System.String value); 
     partial void OnUnitChanged(); 

     /// <summary> 
     /// No hay documentación de metadatos disponible. 
     /// </summary> 
     [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] 
     [DataMemberAttribute()] 
     public global::System.Double UAG23ref 
     { 
      get 
      { 
       return _UAG23ref; 
      } 
      set 
      { 
       OnUAG23refChanging(value); 
       ReportPropertyChanging("UAG23ref"); 
       _UAG23ref = StructuralObject.SetValidValue(value); 
       ReportPropertyChanged("UAG23ref"); 
       OnUAG23refChanged(); 
      } 
     } 
     private global::System.Double _UAG23ref; 
     partial void OnUAG23refChanging(global::System.Double value); 
     partial void OnUAG23refChanged(); 
. 
. 
. 
#endregion 
#region Propiedades de navegación 
. 
. 
. 

#endregion 
} 

重要生成的模型的片段!!!!:我使用的可视化工作室2010年。但如果我在Visual Studio 2013中做同样的工作,它可以工作。在Visual Studio 2010中可能存在一些错误?

+0

它试图存储字符串'0.1'而不是浮点数0.1吗? – Grice 2014-09-19 19:16:27

+0

你是怎么定义你的模型的? – Donal 2014-09-19 19:16:59

+0

你可以请你分享你的viewmodel/model class。 – 2014-09-19 19:17:03

回答

0

也许是文化的问题。尝试在你的web.config中改变它。

<globalization 
requestEncoding="utf-8" 
responseEncoding="utf-8" 
culture="auto" 
uiCulture="auto"/> 

希望它有帮助。

+0

它不起作用 – Cyberguille 2014-09-19 19:58:10