Grid within a razor foreach loop

2 posts, 0 answers
  1. Corey
    Corey avatar
    13 posts
    Member since:
    Sep 2015

    Posted 06 Oct 2015 Link to this post

    Here is my dilema,

    I have a foreach loop over a simple model like this

    Model

    fund list

    fundint int,

    fundname varchar

    etc.

    i am looping through a list of funds above and would like to have a Kendo grid populated with data from the controller for each fundint in the foreach.

            <table>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>@Html.DisplayFor(modelItem => item.FUND_INT_ID)
                        </td>
                    <tr>
                        <td>
                        @(Html.Kendo().Grid<BetaSMTRApp.Models.Private_Report_Card_Companies_Single_Result>()
         .Name("AjaxGrid")
                                    .AutoBind(true)                                                                       .Columns(columns =>
                 {
                                                                                  columns.Bound(c => c.CompanyName).Title("Company Name").Width(150);
                                                                           })
                                                                              .ColumnMenu()
                                                                              .HtmlAttributes(new { style = "height:600px;" })
                                                                              .DataSource(dataSource => dataSource
                                                                                  .Ajax()
                                                                                  .Read(read => read.Action("GetPortfolioCompanies", "PrivateReportCard").Data("additionalInfo"))
                                                                              )
                                        )
                        </td>
     
    <script>
        function additionalInfo() {
            var frominfo = $("#asofdate").val();
            var fundinfo = $("#fundint").val();
            return { AsOfDate: frominfo, FundInt: fundinfo};
        }
    </script>

    How do i pass the FUND_INT_ID in the foreach loop to the GetPortfolioCompanies function in the controller?

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 08 Oct 2015 Link to this post

    Hello Corey,

    You could pass the id via object route value.
    E.g.

    .Read(read => read.Action("ActionName", "ControllerName", new { id = ... }))

    Let me know if this information helps.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top