marufbd / MvcFileUploader

A nuget package for easy blueimp JQuery file upload plugin integration into an ASP.NET Mvc application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing Value to File Uploader

rswetnam opened this issue · comments

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)
{

        <td>
            @Html.DisplayFor(modelItem => item.Id)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>

        <td>
            @(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" })
            )
        </td>

    </tr>
}

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

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" })
            )