开发者

Telerik MVC 3 Grid selected row binding to Model property

I have a Telerik Grid in my View. I want to know if there is a way by which I can bind the Datakey of the selected row to the Model Property -

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site1.Master" Inherits="System.Web.Mvc.ViewPage<Mitek.MobileImagingTest3.Models.JobFileStatisticsModel>" %> 

<% using (Html.BeginForm()) { %>

            <div class="editor-label">       
                <br />                        
               <label>Select Which Job:</label>
            </div>
            <div>
               <%= Html.Telerik().Grid((IEnumerable<Mitek.MobileImagingTest3.Models.JobFileStatisticsModel>)ViewData["JobFilesDataList"])
                        .Name("JobFileGrid")
                        .EnableCustomBinding(true)
                        //.BindTo((IEnumerable<Mitek.MobileImagingTest3.Models.JobFileStatisticsModel>)View开发者_JAVA技巧Data["JobFilesDataList"])
                        .DataKeys(keys => keys.Add(o => o.JobFileId))                       
                        .Columns(columns =>
                        {
                            columns.Bound(o => o.JobFileId).Hidden(true);
                            columns.Bound(o => o.JobFileName).Title("Job File Name").Width(500);
                            columns.Bound(o => o.JobFileVersion).Title("Job File Version").Width(200);
                            columns.Bound(o => o.JobFileDateCreated).Title("Date Created").Format("{0:MM/dd/yyyy}").Width(300);
                        })                            
                        .HtmlAttributes(new { style = "width: 1000px; font-family:arial; font-size: .9em;" })                           
                        .ClientEvents(events => events.OnRowSelected("onRowSelected"))
                        .DataBinding(dataBinding => dataBinding.Ajax().Select("SelectJobFile", "Admin"))                          
                        .Pageable()
                        .Sortable()
                        .Selectable() 
                        .RowAction(row =>
                        {
                            row.Selected = row.DataItem.JobFileId.Equals(ViewData["JobFileId"]);
                            //Model.JobFileId = ViewData["JobFileId"].ToString();
                        })                          
                 %>
               </div>
               <div>

               </div>
               <div>
                    <br />
                   <button type= "submit" name="button" class="t-button"  >Run Report</button>

               </div>

    </div>

    <% } %> 



enter code here


    <script type="text/javascript">

        function onRowSelected(e) {
            var id = e.row.cells[0].innerHTML;            
            alert(id);
        }

    </script>

My model is -

  public class JobFileStatisticsModel
{
    public string JobFileId { get; set; }

    public string JobFileName { get; set; }

    public string JobFileVersion { get; set; }

    public string JobFileDateCreated { get; set; }
}

How do I bind the Datakey of the selected row in the Grid to the Model.JobFileId property? Please help.

Thanks, SDD


Change <Mitek.MobileImagingTest3.Models.JobFileStatisticsModel> to <IEnumerable<Mitek.MobileImagingTest3.Models.JobFileStatisticsModel>>

Also replace

<%= Html.Telerik().Grid((IEnumerable<Mitek.MobileImagingTest3.Models.JobFileStatisticsModel>)ViewData["JobFilesDataList"])

with this line.
<%= Html.Telerik().Grid<Mitek.MobileImagingTest3.Models.JobFileStatisticsModel>(Model)

If you replace both of those it should fix your problem. This is how I am currently doing it so I think it will work. If it doesn't just leave me a message and I will see what else I can come up with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜