1

I was trying to implement drop down in JQGrid. I was using 'select' formatter and it was working fine. But after selection of value and after saved, the data was not showing. Then i read this. I am working with MVC. Here is the code,

{
                            name: 'Sample',
                            index: 'Sample',
                            width: 200,
                            sortable: true,
                            align: 'center',
                            editable: true,
                            cellEdit: true,
                            edittype: 'select',

                            editoptions: {
                                dataUrl: "/mutation/GetSampleData",
                                buildSelect: OwnershipTransfer.getAllSelectOptions

        }

here is ajaxSelectOptions

  ajaxSelectOptions: {
                            type: "GET", 
                            contentType: 'application/json; charset=utf-8',
                            dataType: "json",
                            cache: false,
                        },

Here is getAllSelectOptions:

var getAllSelectOptions = function (data) {
        debugger;
        var html = '<select>', d = data.d, length = d.length, i = 0, item;
        for (; i < length; i++) {
            item = d[i];
            html += '<option value=' + item + '>' + item + '</option>';
        }
        html += '</select>';
        return html;

    }

Here is my method which returns the data,

[HttpGet]
        public ActionResult GetSampleData()
        {
            var list = ShamilatConstants.GetAll();

            return Json(list,JsonRequestBehavior.AllowGet);

        }

The problem is when i edit the row, This method hit. I debugged it. But dropdown is not populated. In console there is a 500 internal server error. What is the problem?

Community
  • 1
  • 1
CodeLover
  • 271
  • 1
  • 3
  • 14
  • Do you verified which format have the `data` inside of `getAllSelectOptions` function? I suppose that `data` have not `d` property (`see `data.d`). I'd recommend you to use `console.log(data)` or just examine the `data` inside of debugger. I suppose that you have to modify the code of `getAllSelectOptions` function to correctly process the data returned from `GetSampleData` action. – Oleg May 12 '16 at 12:49
  • @Oleg I read that, use data.d in case of any type but the problem is In console, there is errror "the server responded with a status of 500 (Internal Server Error)". The execution not come to getAllSelectOptions function. – CodeLover May 12 '16 at 12:52
  • @Oleg i also debugged, GetSampleData method is hitting as well. – CodeLover May 12 '16 at 12:52
  • It's unclear for me which format have `var list` (`ShamilatConstants.GetAll();`). It seems that you get exception in `return Json(list,JsonRequestBehavior.AllowGet);`. Which version of ASP.NET MVC you use? Which version of `Newtonsoft.Json` you use? – Oleg May 12 '16 at 12:56
  • I am using MVC 5 and ShamilatConstants.GetAll(); returns the dictionary.Newtonsoft.Json version is 8.0.3 – CodeLover May 12 '16 at 12:57
  • Could you include at least one item of the dictionary? You can use LINQ to produce `List` from `ShamilatConstants.GetAll()`. Something like `(from item in ShamilatConstants.GetAll() select item.Title).ToList()` where `Title` is just an example of the property – Oleg May 12 '16 at 13:02
  • There are 3 items in the dictionary and i also return a list. It still give same error. – CodeLover May 12 '16 at 13:05
  • @Oleg problem solved. I was returning dictionary which was not serializing. Now i retrun the list. It works. – CodeLover May 12 '16 at 13:16
  • OK, You are welcome! – Oleg May 12 '16 at 13:18
  • @Oleg need your help here. http://stackoverflow.com/questions/37249632/is-there-any-way-to-bind-other-col-when-save-in-jqgrid-in-editmode-with-dataurl – CodeLover May 16 '16 at 09:33

0 Answers0