marufbd / MvcFileUploader

A nuget package for easy blueimp JQuery file upload plugin integration into an ASP.NET Mvc application
MIT License
39 stars 22 forks source link

Passing Value to File Uploader #2

Closed rswetnam closed 11 years ago

rswetnam commented 11 years ago

Hi:

I'd like to use the the MVCFileUploader to upload files associated with rows in a grid.

I've placed the button to call it in a cell in a grid as follows:

@foreach (var item in Model.CourseModules) {

``` @Html.DisplayFor(modelItem => item.Id) @Html.DisplayFor(modelItem => item.Name) @(Html.MvcFileUpload() .UploadAt(Url.Action("UploadFile", "MvcUploaderTest")) //Pass item.Id as int to AddFormField - getting error .AddFormField("entityId", @Html.DisplayFor(modelItem => item.Id)) .RenderPopup("Upload Lesson", "#dlgFileUpload", new { @class = "btn" }) )

}



My problem is that the item.Id (value 162 in my example) does not get passed to the MVCFileUploader when I subsitute the item.Id and various flavours of it for the "1234" that is passed in your demo program.

Any help on how to do this greatly appreciated.

Roger
marufbd commented 11 years ago

AddFormField method takes two string arguments. first one is the key which would be the form field id and second one is the value of that html hidden field submitted with each upload. you should try this

 @(Html.MvcFileUpload()
                .UploadAt(Url.Action("UploadFile", "MvcUploaderTest"))
                //Pass item.Id as string to AddFormField
                .AddFormField("entityId", item.Id.ToString())
                .RenderPopup("Upload Lesson", "#dlgFileUpload", new { @class = "btn" })
            )