How to validate telerik mvc grid using a remote attribute in data annotations?


I want to check if username already exists in database using telerik mvc grid (batch edit). But The problem is in order to validate it, I need to pass applconst_id as a parameter in CheckDuplicateType function. But it always return "undefined", I don't know how to get the right value.

this is my model class:

public class masterTypeCont
    public Int32 applconst_id { get; set; }

    [Required(ErrorMessage = "This field needs a value!")]
        AdditionalFields = "applconst_id",
        ErrorMessage = "Code already exists.")]
    public String note1 { get; set; }

and this is my controller:

    public virtual JsonResult CheckDuplicateType(masterTypeCont tipe, String applconst_id)
        Int32 intID = Convert.ToInt32(applconst_id);
        return Json(typeEnt.ValidateCustomer(intID, tipe.note1), JsonRequestBehavior.AllowGet);

And this is ValidateCustomer function:

public bool ValidateCustomer(Int32 id, String nama) {
        Int32 x = db.appl_const.Where(a =>
           a.group_id == "CH_COMP_CODE" &&
           a.note1.Trim() == nama.Trim() &&
           a.applconst_id != id).Count();

        Boolean res = x == 0 ? true : false;

        return res;

This is my view:

    ViewBag.Title = "Type List";
    Layout = "../Shared/_Layout.cshtml";

<div class="direct-content">
@using (Html.BeginForm())
        .ToolBar(commands =>
        .DataKeys(keys => keys
            .Add(o => o.applconst_id)
        .DataBinding(dataBinding =>
                .Select("_SelectAllType", "Type")
                .Update("_SaveBatchType", "Type");
        .Columns(columns =>
            columns.Bound(o => o.applconst_id).Hidden();
            columns.Bound(o => o.note1).Title("Name");
            columns.Command(commands =>
        .ClientEvents(events => events
    .Editable(editing => editing.Mode(GridEditMode.InCell))
    .Pageable(pager => pager.PageSize(15))
    .Scrollable(x => x.Height("450px"))
    .Resizable(x => x.Columns(true))

    <input type="hidden" name="applconst_id" id="applconst_id" value="1">

I write hidden input there to contains the applconst_id, but still it value doesn't passed to controller.

Sorry for my bad english.

Any help will be deeply appreciated.


Try like this:

public virtual ActionResult CheckDuplicateType(masterTypeCont tipe)
    var result = typeEnt.ValidateCustomer(tipe.applconst_id, tipe.note1);
    return Json(result, JsonRequestBehavior.AllowGet);