In MVC View, I need to pass value from within the model to the controller from a KendoUI Widget

4 posts, 0 answers
  1. L
    L avatar
    5 posts
    Member since:
    Nov 2013

    Posted 29 Aug 2014 Link to this post

    The code below works. The controller receives the value "Test Value" when the Upload widget is executed.However, I have a key value from the model that is displayed within this view that I need to send instead of the hardcoded text.

    Note. This is a custom template within a grid popup editor.


    ViewBag.Title = "Test Value"
    @(Html.Kendo().Upload() .Name("files") .TemplateId("fileTemplate") .Async (a => a .Save("Save", "OpenRecords"), new { MyRequest = ViewBag.Title }) .AutoUpload(true)) )


    public ActionResult Save(IEnumerable<HttpPostedFileBase> files, string MyRequest)
    // The Name of the Upload component is "files"

    if (files != null)
    foreach (var file in files)
    // Some browsers send file names with full path.
    // We are only interested in the file name.

    var fileName = Path.GetFileName(file.FileName);
    var physicalPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
    // The files are not actually saved in this demo
    ViewBag.FileName = fileName;
    //return Content(physicalPath);



    // Return an empty string to signify success
    return Content("");

  2. Dimiter Madjarov
    Dimiter Madjarov avatar
    2310 posts

    Posted 01 Sep 2014 Link to this post

    Hello David,

    I covered this question in the support thread on the same topic. You could try using the following approach.

    I wish you a great day!

    Dimiter Madjarov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. L
    L avatar
    5 posts
    Member since:
    Nov 2013

    Posted 02 Sep 2014 in reply to Dimiter Madjarov Link to this post

    I'm able to get this method to work fine within a normal cshtml file. 

    But it does not work within a Custom Grid Popup Editor template.

    As soon as I attach the ".Upload" event to the Upload widget within the custom breaks the template and the grid no longer functions right and the buttons on the Custom Template no longer work. 

    The Upload widget works fine in the Custom Template and successfully send the File up to the controller UNLESS I add the "Upload" event.   It doesn't matter what the event handler has in it.  


    <h2>Open Records Request</h2>

    @using (Html.BeginForm()) {

            <div class="edit-field">

                <section style="border-top:double; padding-bottom:5px;"/>

                @Html.LabelFor(model => model.RequestID, "Requested ID", new { style = "color:#212a33" })
                @Html.EditorFor(model => model.RequestID, new { style = "width: 40%; font-size:18px; font-family:inherit" })
                @Html.ValidationMessageFor(model => model.RequestID)

                @Html.LabelFor(model => model.CaseRequested, "Report Requested", new { style = "color:#212a33" })
                @Html.TextBoxFor(model => model.CaseRequested, new { style = "width: 40%; font-size:18px; font-family:inherit" })
                @Html.ValidationMessageFor(model => model.CaseRequested)

                @Html.LabelFor(model => model.Organization, "Organization", new { style = "color:#212a33" }))
                @Html.TextBoxFor(model => model.Organization, new { style = "width: 30%; font-size:18px; font-family:inherit" })
                @Html.ValidationMessageFor(model => model.Organization)

            <div class="edit-field">

                @Html.LabelFor(model => model.DateReceived, "Date Received", new { style = "color:#212a33" }))
                @Html.EditorFor(model => model.DateReceived)
                @Html.ValidationMessageFor(model => model.DateReceived)

                @Html.LabelFor(model => model.DateFulfilled, "Date Fulfilled", new { style = "color:#212a33" }))
                @Html.EditorFor(model => model.DateFulfilled)
                @Html.ValidationMessageFor(model => model.DateFulfilled)

                @Html.LabelFor(model => model.Notes, "Notes", new { style = "color:#212a33" })
                @Html.EditorFor(model => model.Notes)
                @Html.ValidationMessageFor(model => model.Notes)
                @Html.LabelFor(model => model.FilePath, "Document", new { style = "color:#212a33" })
                @Html.EditorFor(model => model.FilePath)

                    (a => a
                        .Save("Save", "OpenRecords")
                    (events => events



    @section Scripts {


                function onError(e) {
                    KendoConsole.log("Error ( " + e.operation );

                function onUpload(e) {
           = {
                       MyRequest: $("#RequestID").val()




        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
        .Columns(columns =>
            columns.Bound(dataOpenRecords => dataOpenRecords.RequestID).Hidden(true);
            columns.Bound(dataOpenRecords => dataOpenRecords.DateReceived).Title("Request Received").Format("{0:MM/dd/yyyy}").Width(80);
            columns.Bound(dataOpenRecords => dataOpenRecords.Requestor).Title("Requestor").Width(200);
            columns.Bound(dataOpenRecords => dataOpenRecords.Organization).Title("Organization").Width(200);
            columns.Bound(dataOpenRecords => dataOpenRecords.CaseRequested).Title("Record Requested").Width(200);
            columns.Bound(dataOpenRecords => dataOpenRecords.DateFulfilled).Title("Request Fulfilled").Format("{0:MM/dd/yyyy}").Width(110);
            columns.Bound(dataOpenRecords => dataOpenRecords.Notes).Title("Notes").Width(300);
            columns.Bound(dataOpenRecords => dataOpenRecords.FilePath).Title("Attachment").Width(250)
                .ClientTemplate("<a href='http://tooms/WcfReports/" + Url.Content("#= FilePath #") + "' target='_blank'>#= FilePath #</a>");
            columns.Command(commands =>
        .ToolBar(toolbar =>

        .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("OpenRecordsTemplate"))
        .DataSource(dataSource => dataSource
        .Events(e => e.Error("onError")) // Handle the "error" event (errors set in controller)
        .ServerOperation(false)  // Paging, sorting, filtering and grouping will be done client-side

            .Model(model =>
                    model.Id(dataOpenRecords => dataOpenRecords.RequestID);
                    model.Field(dataOpenRecords => dataOpenRecords.RequestID).Editable(false);
                    model.Field(dataOpenRecords => dataOpenRecords.FilePath).Editable(false);
            .Create(create => create.Action("OpenRecords_Create", "OpenRecords"))
            .Read(read => read.Action("OpenRecords_Read", "OpenRecords"))
            .Update(update => update.Action("OpenRecords_Update", "OpenRecords"))
            .Destroy(destroy => destroy.Action("OpenRecords_Destroy", "OpenRecords"))

            .Events(e => e.Edit("onChange"))
            .HtmlAttributes(new {style = "width:1160px;"})
  4. Dimiter Madjarov
    Dimiter Madjarov avatar
    2310 posts

    Posted 02 Sep 2014 Link to this post

    Hello David,

    I answered this question in the support thead on the same topic. For convenience lets continue the discussion in only one of the threads - forum or support.

    Thanks for the understanding.

    Dimiter Madjarov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top