[英]Remote validation asp.net core telerik grid popup
I have a grid of Countries
, in that I try to remote validate the Code
, that should be unique.我有一个
Countries
网格,因为我尝试远程验证Code
,这应该是唯一的。
public class CountryDTO
{
[HiddenInput(DisplayValue = false)]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
[MaxLength(2)]
[Remote(action: "KeyExist", controller: "Countries")]
public string Code { get; set; }
}
I have in the Views/Shared/EditorTemplates/CountryDTO.cshtml
the following我在
Views/Shared/EditorTemplates/CountryDTO.cshtml
中有以下内容
@model MyApp.Web.ApiModels.CountryDTO
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Code" class="control-label"></label>
<input asp-for="Code" class="form-control" />
<span asp-validation-for="Code" class="text-danger"></span>
</div>
<input type="hidden" asp-for="Id" />
In the CountriesController
:在
CountriesController
中:
[AcceptVerbs("GET", "POST")]
public IActionResult KeyExist([Bind(Prefix ="Code")]string key)
{
if (_countriesService.KeyExist(key, id))
{
return Json($"The Code '{key}' is already used!");
}
return Json(true);
}
but get this when I try to edit the code and leave:但是当我尝试编辑代码并离开时得到这个:
The client request is the following, sending me the right code I tried to insert ("le" in that case)客户端请求如下,向我发送我尝试插入的正确代码(在这种情况下为“le”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.