PopupFormAction in controler

Feb 10, 2011 at 9:11 AM
Edited Feb 10, 2011 at 9:12 AM

I use jquery.jqGrid to display data and when click id then it show pop up.

In my controller  has the following code:

 

 IEnumerable<Organization> organizationView = _organizationService.GetOrganization();


            int pageSize = rows ?? 10;
            int totalRecords = organizationView.Count();
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
            int currentPage = page ?? 1;

            string sortByColumnName = sidx ?? "CustOrgId";
            string sortDirection = sord ?? "desc";

            var organization = (from o in organizationView select o);
            if (sortByColumnName == "CustOrgId")
            {
                if (sortDirection.Equals("desc"))
                    organizationView = organizationView.OrderByDescending(o => o.CustOrgId);
                else
                    organizationView = organizationView.OrderBy(o => o.CustOrgId);
            }
            else
            {
                if ("desc".Equals(sortDirection))
                    organizationView = organizationView.OrderByDescending(o => o.CustOrgName);
                else
                    organizationView = organizationView.OrderBy(o => o.CustOrgName);
            }
            var data = organizationView.Skip((currentPage - 1) * pageSize).Take(pageSize).ToArray();
            var jsonData = new
            {
                total = totalPages,
                page = currentPage,
                records = totalRecords,
                rows = (
                    from o in organizationView
                    select new
                    {
                        i = o.CustOrgId,
                        cell = new string[] {
                            " <a href='javascript:@(Url.PopupFormAction<OrganizationController>(o => o.Info()))'>Edit</a>",
                            "<a href='" + string.Format("./Organization/Delete/{0}", o.CustOrgId.ToString()) + "'>Delete</a>",
                            o.CustOrgId.ToString(),
                            o.CustOrgName
                        }
                    }).ToArray()
            };
            return Json(jsonData, JsonRequestBehavior.AllowGet);

And Razor file :

<script src="/Scripts/jquery.jqGrid.js" type="text/javascript"></script>
<script src="/Scripts/js/jqModal.js" type="text/javascript"></script>
<script src="/Scripts/js/jqDnR.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#list").jqGrid({
            url: '/Organization/DynamicGridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['', '', 'CustOrgId', 'CustOrgName'],
            colModel: [
                          { name: 'Edit', index: 'Edit', width: 80, align: 'left', sortable: false },
                          { name: 'Delete', index: 'Delete', width: 80, align: 'left', sortable: false },
                          { name: 'CustOrgId', index: 'CustOrgId', width: 100, align: 'left' },
                          { name: 'CustOrgName', index: 'CustOrgName', width: 400, align: 'left' }
                       ],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [10, 20, 50, 100, 200],
            sortname: 'CustOrgId',
            sortorder: "desc",
            viewrecords: true,
            imgpath: '/scripts/themes/coffee/images',
            caption: 'My first grid'
        });
        jQuery("#lists").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true });
    });


 function success() {
                alert('country successfully created !');
            }</script>
  @(Html.MakePopupForm<OrganizationController>(o => o.Edit(), "Edit", 200, successFunction: "success"))
<h2>
    My Grid Data</h2>
<table id="list" class="scroll" cellpadding="0" cellspaing="0">
</table>
<div id="pager" class="scroll" style="text-align: center;">
</div>

Please help to fix them ,

Thanks,

 

 

Coordinator
Feb 10, 2011 at 10:41 AM

you are doing this in the controller: " <a href='javascript:@(Url.PopupFormAction<OrganizationController>(o => o.Info()))'>Edit</a>"


i'm not sure, but i guess that there is not going to be any razor parsing or whatever done by the controller

first try putting this link outside the grid in the cshtml and see if it works,

after you can try creating a custom js function  and call it in the controller code so that you would not need any razor parsing

function openInfo(){

@(Url.Popup ... .Info());

}