Максимальная длина 255, предотвращающая отправку формы, несмотря на большую длину StringLength - PullRequest
0 голосов
/ 02 октября 2019

Я пытаюсь создать форму, которая позволит пользователю отправлять новые записи в базу данных SQL Server, которая в конечном итоге будет отображаться на сайте. У меня есть поле Description, которое на стороне сервера является nvarchar (max) . В моей модели я указал длину строки более 255 (т.е. 500, 1000), которую я использовал StringLength(Int32.MaxLength). Я попытался отключить проверку на стороне клиента, полностью исключив проверку из входных данных, и мне не повезло. Но, когда код выполняется локально, он функционирует должным образом и позволяет отправлять формы, но при развертывании на действующем сайте GoDaddy через FTP (с тем же кодом) он по-прежнему выдает ошибку проверки MaxLength The field Description must be a string with a maximum length of 255.

Boar.cs

namespace ShipleySwine
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Data.Entity.Spatial;

    public partial class Boar
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Boar()
        {
            SellingPoints = new HashSet<SellingPoint>();
        }

        [Key]
        [Column(TypeName = "numeric")]
        public decimal Boar_Id { get; set; }

        [StringLength(255)]
        public string Name { get; set; }

        public DateTime? Farrowed { get; set; }

        public int? LitterSize { get; set; }

        public int? Price { get; set; }

        public bool? GuaranteedSettle { get; set; }

        [StringLength(255)]
        public string StressTest { get; set; }

        [StringLength(255)]
        public string NameNoSpaces { get; set; }

        [StringLength(255)]
        public string Sire { get; set; }

        [StringLength(255)]
        public string SireFull { get; set; }

        [StringLength(255)]
        public string Dam { get; set; }

        [StringLength(255)]
        public string DamFull { get; set; }

        [StringLength(255)]
        public string Breed { get; set; }

        public int? Order { get; set; }

        public bool? Featured { get; set; }

        public int? FeaturedOrder { get; set; }

        [StringLength(255)]
        public string EarNotch { get; set; }

        [StringLength(255)]
        public string RegNum { get; set; }

        [StringLength(255)]
        public string TestData { get; set; }

        [StringLength(255)]
        public string BredBy { get; set; }

        [StringLength(255)]
        public string OwnedBy { get; set; }

        [StringLength(500)]
        public string Description { get; set; }

        public DateTime? CreateDate { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<SellingPoint> SellingPoints { get; set; }
    }
}

Create.cshtml (Внизу: поле описания)

@model ShipleySwine.Boar



@{
    ViewBag.Title = "Create";
}

<div class="container backgroundcolor">
    <h2>Create</h2>


    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">
            <h4>Boar</h4>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @*@Html.LabelFor(model => model.Boar_Id, htmlAttributes: new { @class = "control-label col-md-2" })*@
                <label class="control-label col-md-2" for="Boar_id">Boar ID</label>
                <div class="col-md-10">
                    <input name="Boar_id" class="form-control" value="@ViewBag.BoarId" readonly="readonly" />
                    @*@Html.EditorFor(model => model.Boar_Id, new { htmlAttributes = new { placeholder = "Ex: 1" , @class = "form-control" } })*@
                    @Html.ValidationMessageFor(model => model.Boar_Id, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Name, new { htmlAttributes = new { placeholder = "Ex: Gavin", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Farrowed, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Farrowed, new { htmlAttributes = new { placeholder = "Ex: 2015-07-10", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Farrowed, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.LitterSize, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.LitterSize, new { htmlAttributes = new { placeholder = "Ex: 5", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.LitterSize, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Price, new { htmlAttributes = new { placeholder = "Ex: 500", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.GuaranteedSettle, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    <div class="checkbox">
                        @Html.EditorFor(model => model.GuaranteedSettle)
                        @Html.ValidationMessageFor(model => model.GuaranteedSettle, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.StressTest, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.StressTest, new { htmlAttributes = new { placeholder = "Ex: Negative, Carrier", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.StressTest, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.NameNoSpaces, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.NameNoSpaces, new { htmlAttributes = new { placeholder = "Ex: GavinNoSpaces", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.NameNoSpaces, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Sire, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Sire, new { htmlAttributes = new { placeholder = "Ex: Daddy Boar", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Sire, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.SireFull, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.SireFull, new { htmlAttributes = new { placeholder = "Ex: Daddy Boar Full Name", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.SireFull, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Dam, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Dam, new { htmlAttributes = new { placeholder = "Ex: Mommy Boar", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Dam, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.DamFull, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.DamFull, new { htmlAttributes = new { placeholder = "Ex: Mommy Boar Full Name", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.DamFull, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Breed, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Breed, new { htmlAttributes = new { placeholder = "Ex: Yorkshire, Berkshire,Duroc", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Breed, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Order, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Order, new { htmlAttributes = new { placeholder = "Ex: 5", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Order, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Featured, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    <div class="checkbox">
                        @Html.EditorFor(model => model.Featured)
                        @Html.ValidationMessageFor(model => model.Featured, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.FeaturedOrder, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.FeaturedOrder, new { htmlAttributes = new { placeholder = "Ex: 5", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.FeaturedOrder, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.EarNotch, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.EarNotch, new { htmlAttributes = new { placeholder = "Ex: E.N.: 23-5", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.EarNotch, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.RegNum, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.RegNum, new { htmlAttributes = new { placeholder = "Reg #: 490946005", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.RegNum, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.TestData, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.TestData, new { htmlAttributes = new { placeholder = "158 days to 250# 0.51 BF 9.38 LE", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.TestData, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.BredBy, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.BredBy, new { htmlAttributes = new { placeholder = "Bred By: Farrer Stock Farm (IN)", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.BredBy, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.OwnedBy, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.OwnedBy, new { htmlAttributes = new { placeholder = "Owned By: Shipley Swine Genetics, Snyder Berks and Austin Lane", @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.OwnedBy, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Description, new { htmlAttributes = new { placeholder = "Add something here", @class = "form-control" } })

                    @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10 text-center">
                    <input type="submit" value="Create" class="btn btn-primary" />
                </div>
            </div>
        </div>
    }

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

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...