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

Kendo Upload file is sending null in the controller when i send other values as parameters

1 Answer 904 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Juan
Top achievements
Rank 1
Juan asked on 21 Nov 2016, 04:19 PM

This is the situation: I have a form that when i click in the submit button is sending a file with the kendo upload control, and the method action of the controller is receiving that file in the parameter with the HttpPostedFileBase.
This is my HTML code:

 

@using (Html.BeginForm("ConfirmarOposicion", "Gestion", FormMethod.Post, new { @id = "Frm-login", role = "form", @class = "form-horizontal" }))

{

    @(Html.Kendo().Upload()

        .Name("files")

    )

    <button class="btn btn-success" type="submit" id="confirm" >Confirm</button>

}

And this is my controller:

public async Task<ActionResult> ConfirmarOposicion(IEnumerable<HttpPostedFileBase> files)

{

    // Here the parameter files is not null..

}

Here is working all good till now. The problem is when i try to send more values as parameter into the same method of the controller. The other values that i want to send is an array, and the other is a number. This two values i try to send with ajax in javaScript.
This is my javaScript code when i try to send those two more values:

$("#confirm").click(function ()

{

    var numMarca = $("#numMarca").val()

    var idsToSend = [];

    var grid = $("#Grid2").data("kendoGrid")

    var ds = grid.dataSource.view();

    for (var i = 0; i < ds.length; i++)

    {

        var row = grid.table.find("tr[data-uid='" + ds[i].uid + "']");

        var checkbox = $(row).find(".checkbox");

        if (checkbox.is(":checked"))

        {

            idsToSend.push(ds[i].DescMarca);

            idsToSend.push(ds[i].IntencionOposicion = 1);

        }

        else

        {

            idsToSend.push(ds[i].DescMarca);

        }

    }

    $.ajax({

        url: '@Url.Action("ConfirmarOposicion", "Gestion")',

        data: { ids: idsToSend, marca: numMarca },

        type: 'POST',

        dataType: "json",

        success: function (data)

        {

             ...

        }

 

When i clik the submit button is sending this two values in the same controller that i send the input file.
And this my controller now:

public async Task<ActionResult> ConfirmarOposicion(IEnumerable<HttpPostedFileBase> files, string[] ids, string marca)

{

    // here the array ids and the value of marca is not null, but the parameter files it is null

}

And that's the issue that i have.
I need to send all those values in the same method action of the controller.
How can i do that?

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 23 Nov 2016, 02:38 PM
Hello Juan,

The described behavior is expected because you are not sending the files when executing the ajax request. As this is not related to the Kendo UI Upload's API, it is a task for the developer to implement the correct post request to the controller. Nevertheless, we would suggest you to review the Asynchronous mode of the Upload where you could send additional parameters along with the files: Send Metadata to Save Actions

Another option is to use hidden inputs with names "ids" and "marca" and in the submit event handler to assign them values. 

<script>
   $("#Frm-login").on("submit", function (e)
   {
      // assign values to the hidden inputs here..       
        
   })
    </script>

Regards,
Peter Milchev
Telerik by Progress
Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Tags
Upload
Asked by
Juan
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or