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

Get selected row column value, update modelview

1 Answer 579 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GCS
Top achievements
Rank 1
GCS asked on 04 Feb 2014, 11:55 PM
Using Kendo Grid in an MVC application. 

The primary model for the View (PlanViewModel) contains a property which is a foreign key to another entity (BuildingId) For instance, 

    public class PlanViewModel
    {
        
        public int PlanId { get; set; }
        public string PlanName { get; set; }
        public int BuildingId { get; set; }
        ...
}

The Building ID is to be populated by the selected row of a BuildingGrid on the View. 

So with the BuildingGrid, I'm using the .Selectable setting to invoke an onChange event.  How in the following event would I update the model.BuildingId 

    function onChange(arg) {
        var selected = $.map(this.select(), function (item) {
            return $(item).text();
        });
        
        /// UPDATE MODEL BuildingId here

    }


Thanks! 






1 Answer, 1 is accepted

Sort by
0
GCS
Top achievements
Rank 1
answered on 06 Feb 2014, 03:48 PM
Figured it out. First, I associated an Html attribute to the model property like so: 

    @Html.HiddenFor(m => m.BuildingID, new {id = "Id"})

Then I added the following jquery script: 

    $('#BuildingGrid').click(function() {
        var gview = $(this).data("kendoGrid");
        var selectedItem = gview.dataItem(gview.select());
        var BuildingId = selectedItem.BuildingId;
        $("#Id").val(BuildingId);
    });


That set the Model.BuildingId perfectly. 
Tags
Grid
Asked by
GCS
Top achievements
Rank 1
Answers by
GCS
Top achievements
Rank 1
Share this question
or