This is a migrated thread and some comments may be shown as answers.

the notorious error: parameters dictionary contains a null entry for parameter 'id' of non-nullable type

3 Answers 861 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Max
Top achievements
Rank 1
Max asked on 05 Dec 2011, 05:43 PM

Hi all

I keep getting the error below when I try to update my row:

"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult _UpdateAjaxEditing(Int32)"

I have tried the following:

- changing the grid from popup to inline;
-used [ScaffoldColumn(false)] in a few primite properties;
-used ModelState.Remove("ID");
-used Fiddler and saw that all values are being passed;
-create my own ViewModels;

What is interesting is that I get the 500 server error but the method  "_UpdateAjaxEditing" is never called(I have a breakpoint there).

ViewModel:
===========
    public class SccmSiteViewModel
    {
        //[ScaffoldColumn(false)]
        public Guid ID;
        public string Code { get; set; }
        public string Size { get; set; }
    }
 
Controller:
============
    public class SccmSiteController : Controller
    {
        private UnitOfWork unitOfWork = new UnitOfWork();
 
        public ActionResult Index()
        {
            return View();
        }
 
        [GridAction]
        public ActionResult _SelectAjax()
        {
            var model = from e in unitOfWork.SccmSiteRepository.Get()
                        select new SccmSiteViewModel
                        {
                            ID = e.ID,
                            Code = e.Code,
                            Size = e.Size
                        };
 
            return View(new GridModel { Data = model });
        }
 
        [GridAction]
        public ActionResult _UpdateAjax(int id)
        {
          //this action is never called due to the 500 server error
      //some code here...
        }
 
View:
======
@model IEnumerable<.Web.ViewModels.SccmSiteViewModel>
          
@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.ID);
        })
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
            .Select("_SelectAjax", "SccmSite")
            .Update("_UpdateAjax", "SccmSite");
        })
        .Columns(columns =>
        {
            columns.Bound(p => p.Code).Width(130);
            columns.Bound(p => p.Size);
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(buttonType);
            }).Title("Commands");
        })
        .Editable(editing => editing.Mode(gridEditMode))
)


Any help is appreciated.

Thanks

3 Answers, 1 is accepted

Sort by
0
Max
Top achievements
Rank 1
answered on 06 Dec 2011, 07:00 AM
For the people who might have the same issue ...
I found the problem. It was wrong signature on the Action method.

It seems that I cannot delete my own posts or mark as anwered...anyways...it's solved.
0
David
Top achievements
Rank 1
answered on 30 Jan 2013, 03:18 PM
I'm having the same problem. What did you change your action method signature to?
0
Bob
Top achievements
Rank 1
answered on 10 May 2013, 08:33 PM

What fixed it for me was adding the question mark after the datatype "decimal" defining my one paramater, "rate" (see snippet below).  When I clicked the "Cancel" button, it calls the Copy, ActionResult.  The parameter needed the question mark to fix the null value in the dictionary error. 

Also, I had serveral parameters because I'm displaying several fields in each row, but since I'm only updating one value, "rate", I only needed that one parameter.  I removed the parameters for all the "non-editable" fields. Maybe that's what he was referring to by a wrong signiture?  Anyway, hope this helps.

ActionResult Copy(GridEditMode? mode, GridButtonType? type, decimal? rate)

 { .... }

 

 

Tags
Grid
Asked by
Max
Top achievements
Rank 1
Answers by
Max
Top achievements
Rank 1
David
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Share this question
or