Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using webgrid in MVC it working fine, its edit delete and paging action working fine.But I have some extra requirement in page load we have 2 dropdown so on the basis of dropdown we have to bind my webgrid.
So implement this functionality i am creating webgrid from controller so everything is fine but paging and Edit delete is not showing.How we achieve this....

i have done webgrid for 1 st time load in View Section like -
VB
@grid.GetHtml(htmlAttributes: new {id = "Gridv"},
    fillEmptyRows: true,
    alternatingRowStyle: "alternate-row",
    headerStyle: "grid-header",
    footerStyle: "grid-footer",
    mode: WebGridPagerModes.All,
    firstText: "<< First",
    previousText: "< Prev",
    nextText: "Next >",
    lastText: "Last >>",
    columns: new [] {
    grid.Column("Ordinal"),
    grid.Column("CourseName",header:"Course Name"),
    grid.Column("CourseDisplatTitle",header:"Description"),
    grid.Column("LanguageName",header:"Language"),
    grid.Column("ThemeName",header:"Theme"),
    grid.Column("LinkedCourses"),
    grid.Column("Enabled",header:"Active"),
    //grid.Column("FriendlyId", style:"hidecol",header:""),
    grid.Column(null,null, format: @<input type="hidden" name="IDHidden" value="@item.FriendlyId"/>),

    grid.Column("",
     header: "Actions",
     format: @<text>
     @Html.ActionLink("Edit",   "EditCourse",   new { id=item.CourseId} )
      |
     @Html.ActionLink("Delete", "DeleteCourse", new { id=item.CourseId} , new { onclick="return confirm('Are you sure?');"})
     </text>
        )
})




but in 2 nd time when we do filter we are doing in controller like-
C#
[HttpGet]
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CustomDataAll()
        {
            var tms = BusinessLayer.ThemeManager.GetThemes().ToList();
            var crs = BusinessLayer.CourseManager.GetCourses().ToList();
            var por = BusinessLayer.PortalManager.GetPortals();
            var mod = BusinessLayer.ModuleManager.GetModules().ToList();
            var result = from c in crs
                         join th in tms on c.ThemeId equals th.Id
                         //where c.ThemeId == themeid
                         join pr in por on th.PortalId equals pr.Id // where th.PortalId==portalid
                         join m in mod on c.Id equals m.CourseId into modules
                         select new
                         {
                             CourseId = c.Id,
                             CourseName = c.Name,
                             ThemeId = th.Id,
                             ThemeName = th.Name,
                             LanguageID = pr.Id,
                             LanguageName = pr.Name,
                             FriendlyId = c.FriendlyId,
                             Ordinal = c.Ordinal,
                             CourseDisplatTitle = c.CourseDisplayTitle,
                             Enabled = c.Enabled,
                             LinkedCourses = modules.Count()
                         };
            var grid = new System.Web.Helpers.WebGrid(result);

            var htmlString = grid.GetHtml();
return Json(new
            {
                Data = htmlString.ToHtmlString()
            }
                , JsonRequestBehavior.AllowGet);
        }

I am not able to implement edit delete and paging functionality in this 2 section...which ajax funtion is using in 2nd time is like this-

C#
<script type="text/javascript">
    $(function () {
        $('#modTheme_DataValueField').change(function () {
            var selectedValue = $(this).val();
            if (selectedValue != "") {
                $.ajax({
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    url: '@Url.Action("CustomData", "ContentUpload")',
                    data: { "themeid": selectedValue },
                    dataType: "json",
                    beforeSend: function () {
                        //alert(id);
                    },
                    success: function (data) {
                        var items = "";
                        var i = 0;
                        $('#Gridv').html(data.Data);

                    },
                    error: function (result) {
                        //alert('Service call failed: ' + result.status + ' Type :' + result.statusText);
                    }
                });
            }
            else {
                $.ajax({
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    url: '@Url.Action("CustomDataAll", "ContentUpload")',
                    data: { },
                    dataType: "json",
                    beforeSend: function () {
                        //alert(id);
                    },
                    success: function (data) {
                        var items = "";
                        var i = 0;
                        $('#Gridv').html(data.Data);

                    },
                    error: function (result) {
                        alert('Service call failed: ' + result.status + ' Type :' + result.statusText);
                    }
                });
            }
        });
    });

</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900