您输入的值对此字段无效

时间:2014-09-19 19:14:16

标签: c# asp.net-mvc

我有数据库的暂停表,我使用的是Microsoft SQL Server 2008 R2,这是我的表:

enter image description here

我在ASP.NET MVC应用程序中使用Entity Framework实现了基本的CRUD功能(参见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
}

重要!!!!:我使用的是visual studio 2010.但是如果我对visual studio 2013做同样的事情,那就有效。在Visual Studio 2010中可能有一些错误吗?

1 个答案:

答案 0 :(得分:0)

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

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

希望它有所帮助。