提问人:n_dev 提问时间:7/22/2022 最后编辑:n_dev 更新时间:2/8/2023 访问量:174
我的jQuery验证没有验证表单?
my jQuery-validation not validating the form?
问:
我已经创建了部分视图,并且在我的表单中,我添加了 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/[email protected]/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; }
}```
答:
0赞
n_dev
7/23/2022
#1
是的,我发现了问题,我的标签助手不起作用,因为我的共享文件夹和_viewImport文件在页面中,但我使用的是“查看”文件夹中的剃须刀页面。
评论