【问题标题】:Remote validation asp.net core telerik grid popup远程验证asp.net核心telerik网格弹出
【发布时间】:2021-05-09 14:12:34
【问题描述】:

我有一个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; }
}

我在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" />

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);
    }

但是当我尝试编辑代码并离开时得到这个:

客户端请求如下,向我发送我尝试插入的正确代码(在这种情况下为“le”)

【问题讨论】:

    标签: c# validation asp.net-core telerik-grid .net-5


    【解决方案1】:

    已解决,通过更改此code

    $.ajax({
        url: url,
        type: "POST",
        data: JSON.stringify(postData),
    

    到这个

    $.ajax({
        url: url,
        type: "GET",
        data: postData,
    

    在 Grid 的 CSHTML 脚本标签中....(详细了解客户端脚本 here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      • 2017-01-04
      • 1970-01-01
      • 2017-05-13
      • 2019-08-05
      • 2021-06-26
      • 1970-01-01
      相关资源
      最近更新 更多