我的jQuery-validation没有验证表单?

z31licg0  于 2023-02-03  发布在  jQuery
关注(0)|答案(1)|浏览(186)

我创建了部分视图,并在表单中添加了jquery验证和不显眼的jquery,但表单总是为('form '). valid()返回true。
控制台端没有错误。请任何人帮助。

<form id="addform"
                  @*@Url.Action(@name.ToString())*@
                  data-ajax="true"
                  data-ajax-begin="onSubmit"
                  data-ajax-url="/@name"
                  data-ajax-success="onSuccess"
                  data-ajax-failure="error"
                  data-ajax-method="POST">
                <input type="hidden" id="cus_id" name="id" value="@Model.ProductId" />
                <label>Name</label>
                <input type="text" id="name" class="form-control" asp-for="Name" value="@Model.Name" />
                <span asp-validation-for="Name" class="text-danger"> </span>
                <br />
                <label>Price</label>
                <input type="number" min="0" id="fname" class="form-control" asp-for="price" value="@Model.Price" />
                <span asp-validation-for="Price" class="text-danger"> </span>
                <br />
                <label>Description</label>
                <input type="text" id="phone" class="form-control" asp-for="Descritpion" value="@Model.Description" />
                <span asp-validation-for="Description" class="text-danger"> </span>

                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary">Save</button>
                </div>
            </form>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.js"> </script>
    <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"> </script>

以下是模型类

{
        public int ProductId { get; set; }
        [Required(ErrorMessage = "The Name is Required")]

        //[Remote("validateName", "product", ErrorMessage = "This Name is Already Exisit")]
        [Remote("ValidateCode", "product", ErrorMessage = "Please enter a valid code")]
        public string Name { get; set; }
        [Required(ErrorMessage = "The price is Required")]

        public decimal Price { get; set; }
        [Required(ErrorMessage = "The Description is Required")]
        public string Description { get; set; }

    }```
332nm8kg

332nm8kg1#

是的,我发现问题是我的标记助手不工作,因为我的共享文件夹和_viewImport文件在页面中,但我使用的是视图文件夹中的剃刀页面。

相关问题