C # ASP.NET RAZOR: двойная проверка - PullRequest
0 голосов
/ 04 марта 2019

Пожалуйста, помогите: валидатор не проверяет двойное значение:

Когда я набираю значение Double с точкой или вербулой, валидатор отображает мне сообщение об ошибке, что значение недопустимо:

когда я набираю значение в vergule, он выдает мне следующее сообщение: Поле LONGITUDE должно быть числом.

, а когда я набираю значение с точкой, он выдает мне следующее сообщение: Значение "230.5" равнонедействительно для ОТНОШЕНИЯ.

See Exemple

это код вида:

@model Miam.Models.diverse_info_commerce

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


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

    <div class="form-horizontal">
        <h4>diverse_info_commerce</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.ID_COMMERCE, "ID_COMMERCE", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("ID_COMMERCE", null, htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.ID_COMMERCE, "", new { @class = "text-danger" })
            </div>
        </div>

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

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

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

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

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

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

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

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

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

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

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

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

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

Модель:

namespace Miam.Models
{
    using System;
    using System.Collections.Generic;

    public partial class diverse_info_commerce
    {
        public int ID_POSITION { get; set; }
        public Nullable<int> ID_COMMERCE { get; set; }
        public string VILLE { get; set; }
        public string RUE { get; set; }
        public int NUMERO { get; set; }
        public double LONGITUDE { get; set; }
        public double ATTITUDE { get; set; }
        public string PAYS { get; set; }
        public System.DateTime HEUR_OUVERTURE { get; set; }
        public System.DateTime HEUR_FERMETURE { get; set; }
        public System.DateTime CREATED_AT { get; set; }
        public System.DateTime UPDATED_AT { get; set; }

        public virtual commerce commerce { get; set; }
    }
}

Контроллер:

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ID_POSITION,ID_COMMERCE,VILLE,RUE,NUMERO,LONGITUDE,ATTITUDE,PAYS,HEUR_OUVERTURE,HEUR_FERMETURE")] diverse_info_commerce diverse_info_commerce)
 {
       if (ModelState.IsValid)
       {
             diverse_info_commerce.UPDATED_AT = DateTime.Now;
             diverse_info_commerce.CREATED_AT= DateTime.Now;

             db.diverse_info_commerce.Add(diverse_info_commerce);
             await db.SaveChangesAsync();
             return RedirectToAction("Index");
        }

        ViewBag.ID_COMMERCE = new SelectList(db.commerces, "ID_COMMERCE", "TITRE_COMMERCE", diverse_info_commerce.ID_COMMERCE);
        return View(diverse_info_commerce);
 }
...