user1399216
user1399216

Reputation: 35

Telerik MVC Grid Delete issue, Delete doesn't pass string key value to controller

I can't tell if the following issue is my code or a Telerik bug. Thanks for any help.

My Telerik .cshtml code looks like the following. Note that s.ID is a string not an integer.

...
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(s => s.ID))
.DataBinding(dataBinding =>
    {
        dataBinding.Server()
        .Select("Edit", "DataImport")
        .Insert("Insert", "DataImport")
        .Update("Save", "DataImport")
        .Delete("Delete", "DataImport");
    })
.Columns(columns =>
...

On the controller side:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(string key) // Here, the key comes in as null

However, with the Save method it works. "key" in the following is correctly set to the string key value of the row.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save(string key, Model model) // Here, the key is correct

In both cases the URL looks right, e.g. .../Delete/keyHere

Upvotes: 1

Views: 1306

Answers (1)

Igorrious
Igorrious

Reputation: 1618

I agree with CD Smith double check your data types. If you want to pass your "ID" field to the controller under the variable name "Key". You need to use the RouteKey() method.

.DataKeys(keys => keys.Add(s => s.ID).RouteKey("Key"))

Upvotes: 3

Related Questions