Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC
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 -
@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-
[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-
 
<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 24-Apr-13 23:44pm
rummer845

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 25 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100