I am using an editor template to edit an entity that is represented by a view model. I have a grid in the editor template that in order to bind needs to have the primary key of the model passed to it in order to bind the images. How do I accomplish this?? Here is what I am currently doing which is NOT working:
From the grid .DataSource property:
"bind_images" javascript function:
"BindImages" method in the controller:
What is happening is that in the javascript function, the "Key" is always the previously edited record (because I don't know how to get the ID of the record beign currently edities, it looks like I am just grabbing the key of the selected row which is always going to be 1 behind). SO my first issue is how do I get the key of the row being edited?
Secondly, even when a valid ID is passed to the controller method and data is returned, it is never loaded into the grid. What am I doing wrong?
Instead of the .Data and passing a javascript function can't I just add to the route values using the .Route property? If so, how?
Any help is appreciated. Thanks!!
From the grid .DataSource property:
.Read( read => read.Action( "BindImages", "CatalogAdministration" ).Data( "bind_images" ) )
"bind_images" javascript function:
function
bind_images() {
var
grid = $(
"#GridInventoryItems"
).data(
"kendoGrid"
);
grid.select().each(
function
() {
var
dataItem = grid.dataItem($(
this
));
key = dataItem.InventoryItemId;
});
return
{
inventoryItemId: key
};
}
"BindImages" method in the controller:
public
JsonResult BindImages(
int
? InventoryItemId )
{
JsonResult result =
null
;
if
( InventoryItemId.HasValue )
{
result = Json( _GetImageViewModelRecords( InventoryItemId ) );
}
return
result;
}
What is happening is that in the javascript function, the "Key" is always the previously edited record (because I don't know how to get the ID of the record beign currently edities, it looks like I am just grabbing the key of the selected row which is always going to be 1 behind). SO my first issue is how do I get the key of the row being edited?
Secondly, even when a valid ID is passed to the controller method and data is returned, it is never loaded into the grid. What am I doing wrong?
Instead of the .Data and passing a javascript function can't I just add to the route values using the .Route property? If so, how?
Any help is appreciated. Thanks!!