This is a migrated thread and some comments may be shown as answers.

[Solved] Ajax Databinding Update parameters

3 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Greg
Top achievements
Rank 1
Greg asked on 01 Dec 2011, 10:05 PM
Hello,

I have been attempting to pass two values to my controller from my update and delete commands on my grid.
I have been unable to figure out how to get the current value from the editable grid row to be passed as the value to the controller.
The examples show <#= OrderKey #> as the syntat to use as the use to accomplsh the task but it is passed as plain text.

Would Like Value From Row is where I would like to row value

Any help?

Here is an example of my grid as well as my controller. I am using Razor Syntax.

 <div>         
@{Html.Telerik().Grid(Model.Designs).Name("orderDesignModel").PrefixUrlParameters(false)         
.DataKeys(dataKeys =>              
{                 
dataKeys.Add(c => c.Key).RouteKey("Key");                 
dataKeys.Add(c => c.OrderKey);             
})         
.ToolBar(commands => commands.Insert())         
.DataBinding(dataBinding => dataBinding             
.Ajax()             
.Select("IndexOrderDesignModel""Order")             
.Insert("InsertOrderDesignModel""Order")             
.Update("UpdateOrderDesignModel""Order"new { mainId = Model.Key, subId = "Would Like Value From Row" })
.Delete("DeleteOrderDesignModel""Order"new { mainId = Model.Key, subId = "Would Like Value From Row" }) )         
.Columns(columns =>         
{             
columns.Add(c => c.Key).Hidden();             
columns.Add(c => c.Name).Width(200);             
columns.Add(c => c.Description);             
columns.Add(c => c.DueDate);             
columns.Add(c => c.DeliveryAddress);             
columns.Add(c => c.ShippedDate);             
columns.Command(commands => commands.Edit());             
columns.Command(commands => commands.Delete());         
})         
.Filterable()
.Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn))
.Pageable()
.Scrollable(scrolling => scrolling.Height(250))
.Render();}     
</div>


[HttpPost]         
[GridAction(GridName = "orderDesignModel")]         
public ActionResult UpdateOrderDesignModel(string mainId, string subId)         
{
//Removed Extra Text            
return View(new GridModel(_orderRepository.All()));         
}

3 Answers, 1 is accepted

Sort by
0
Jared
Top achievements
Rank 1
answered on 02 Dec 2011, 09:15 PM
Wait, what value do you want to send from the row?
0
Greg
Top achievements
Rank 1
answered on 05 Dec 2011, 04:52 PM
I would like tio have the update send the name column when a update is called

I have tried the following without result

.Update("UpdateOrderDesignModel", "Order",
new { mainId = Model.Key, subId = "<#= Name #>"})

I just get the string "<#= Name #>" as the value of subId in the controller method.
0
Sam Rossetti
Top achievements
Rank 1
answered on 25 Apr 2012, 03:07 AM
I'm not 100% sure about this as I'm still new to using the Telerik MVC Grid but here goes...

Assuming the field "Key" is the value you want when setting the DataKeys try setting the RouteKey as "SubId" like this.

dataKeys.Add(c => c.Key).RouteKey("subId");


After that change the commands like this.

.Update("UpdateOrderDesignModel", "Order", new { mainId = Model.Key })
.Delete("DeleteOrderDesignModel", "Order", new { mainId = Model.Key }) )

When you post up to the controller the MVC engine should parse out the subId from the form values.

I have tried to the <#= Name #> as posted below with varying levels of success. So far it has only worked for me on a detail grid with values from the parent grid.
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Jared
Top achievements
Rank 1
Greg
Top achievements
Rank 1
Sam Rossetti
Top achievements
Rank 1
Share this question
or