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

[Solved] Accessing row object in ClientRowTemplate

2 Answers 43 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.
Noah
Top achievements
Rank 1
Noah asked on 20 Oct 2011, 02:40 PM
Is it possible to access the attributes of the current object when NOT in the raw string of the client row template?  I am trying to add an upload button to a client row template, and I need the async method to know the id of the object in that template

class MyModel {
int Id;
string Name;
}

I know i can use <#= Id #> in the string part of the template, but is there any way to reference it a part of the template that is code?
...
@(Html.Telerik().Grid<MyModel>().ClientRowTemplate( grid =>
    "<div> <#= Name #></div><div>Add attachment: " +
    Html.Telerik().Upload().Name("foobar")
        .Async(a => a.Save("Save", "MyModel", new { id = ****HOW DO I GET THE CURRENT ID HERE???***})).ToHtmlString()
)
)

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 21 Oct 2011, 06:42 AM
Hello Noah,

 You can use the OnUpload event of your upload. Here is a quick example:

.ClientRowTemplate(grid => Html.Telerik().Upload().Name("foobar_<#= Id #>")
   .ClientEvents(e => e.OnUpload("onUpload"))
   .Async(a => a.Save("Save", "Upload")).ToHtmlString()
)

<script>
function onUpload(e) {
    var grid = $("#Grid").data("tGrid");
 
    var tr = $(this).closest("tr");
 
    var dataItem = grid.dataItem(tr);
  
    e.data = $.extend(e.data, {
        id: dataItem.Id
    });
}
</script>

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Noah
Top achievements
Rank 1
answered on 21 Oct 2011, 04:59 PM
thanks, that worked.  I had to get the file directly from the request since the name attribute no longer matched the action method parameter name...

[HttpPost]
public ActionResult AddAttachment(int id)
{
    HttpPostedFileBase attachment = Request.Files[0];
     
   //.... STUFF ...
 
    return Content("");
}
Tags
Grid
Asked by
Noah
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Noah
Top achievements
Rank 1
Share this question
or