0
votes

I am using a Telerik MVC grid to let the users manage the reports in the system. I built an EditorTemplate with some fields in it and with an uploader from Telerik.

I want to pass the ReportId to the uploader method so that it knows the report record to which the file belongs.

@model MyMvcApp.Models.ReportModel

@Html.DisplayFor(t => t.ReportID)

@Html.HiddenFor(t=> t.ReportID)

@(Html.Telerik().Upload()
          .Name("attachments")
          .Multiple(false)
          .Async(async => async.Save("Save", "Report", 
                            new { Id = Model.ReportID })
          .AutoUpload(true)
))

However, the Model.RaportId returns an empty GUID.

Also, the @Html.DisplayFor(t => t.ReportID) doesn't work properly.

But the @Html.HiddenFor(t=> t.ReportID) works just fine when I inspect the page.

I know that Telerik is building a dummy model when creating the editor template. But what can be done?

  • Use javascript to populate a ViewBag variable and use that in the save method?
  • Call the model in a different way?

All in all, I have now changed to using separate views for create/update, but I'd like to build this into the grid. The experience would be better.

2
Are there any DataAnnotations on your ReportId field like this ? [HiddenInput(DisplayValue = false)] - Superzadeh
No. The problem has to be somewhere else. - Ovi

2 Answers

0
votes

I think you may need to leverage the OnUpload method from Telerik MVC's Client API.

This method gives you access to the data before the upload request is sent. So, you have a place to debug the upload data, and if it is not correct then you can manipulate it (e.g. add the correct ReportID parameter).

0
votes

I had the same issue and started searching. According to telerik, the Display templates are not supported in ajax edit mode . I think it makes sense as the edit mode pops up almost instantaneously. You will need to use the grid's OnEdit event.

I am using a disabled text box for now like the following.

 @Html.TextBoxFor(model => model.ReportId, new { disabled = "disabled" })