简体   繁体   English

远程验证 asp.net 核心 telerik 网格弹出

[英]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”) 在此处输入图像描述

Solved, by changing this code :通过更改此代码解决了:

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

to this one对这个

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

in the Grid's CSHTML script tag.... (details on the client side script here )在 Grid 的 CSHTML 脚本标签中......( 这里有关于客户端脚本的详细信息)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM