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

GridEditMode.PopUp fails but GridEditMode.InLine

6 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
HaBo
Top achievements
Rank 1
HaBo asked on 01 Nov 2017, 12:17 PM

if I change GridEditMode.PopUp to GridEditMode.InLine it works, but when it is in PopUp mode, it throws following error

The model item passed into the dictionary is of type 'OfficeGx.Pms.Model.WorkStatus', but this dictionary requires a model item of type 'System.Int32'.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'OfficeGx.Pms.Model.WorkStatus', but this dictionary requires a model item of type 'System.Int32'.

Source Error: 

Line 1: @using OfficeGx.Pms.Model.NonDb Line 2: @(Html.Kendo().Grid<OfficeGx.Pms.Model.WorkStatus>() Line 3: .Name("WorkStatusGrid") Line 4: .Columns(columns =>
Source File: Status.cshtml    Line: 2 

Here is my Grid Code

@using OfficeGx.Pms.Model.NonDb
@(Html.Kendo().Grid<OfficeGx.Pms.Model.WorkStatus>()
      .Name("WorkStatusGrid")
      .Columns(columns =>
      {
          columns.Bound(c => c.Id);
          columns.Bound(c => c.Name);
          columns.Bound(c => c.Style.BackgroundColor).ClientTemplate("# if(typeof Style!='undefined') { #<span>#:Style.BackgroundColor#</span># } else { #''# }#");
          columns.Bound(c => c.Description).Width(150);
          columns.Bound(c => c.DisplayOrder);
          columns.Bound(c => c.CreatedDateUtc).Format("{0:dd/MM/yyyy HH:mm}");
          columns.Bound(c => c.ModifiedDateUtc).Format("{0:dd/MM/yyyy HH:mm}");
          columns.Bound(c => c.IsDefault).EditorTemplateName("BooleanForWorkConfigDefault")
              .HtmlAttributes(new { @class = "default-checkbox-status" });
          columns.Command(command =>
          {
              command.Edit().Text(" ");
              command.Destroy().Text(" ");
          });
      })
    //.Scrollable()
    .Groupable()
    .Sortable().ColumnMenu()
      .ToolBar(toolbar =>
      {
          toolbar.Create();
          //toolbar.Save();
      })
      .Editable(editable =>
                editable.Mode(GridEditMode.InLine)
                .Window(x => x.Width(600).Title("Add/Edit Status")))
      .Pageable(pageable => pageable
          .Refresh(true)
          .PageSizes(true)
          .ButtonCount(5))
      .Resizable(resize => resize.Columns(true))
      .Reorderable(reorder => reorder.Columns(true))
      .DataSource(dataSource => dataSource
          .Ajax()
          .Sort(sort => sort.Add(x => x.DisplayOrder).Ascending())
          .Batch(true)
          .Model(model =>
          {
              model.Id(x => x.Id);
              model.Field(c => c.Id).DefaultValue(0).Editable(false);
 
              model.Field(x => x.Name).Editable(true);
              //model.Field(x => x.Style).DefaultValue(new Style()).Editable(true);
              model.Field(x => x.Style.BackgroundColor).Editable(true);
              model.Field(x => x.DisplayOrder).Editable(true);
              model.Field(c => c.Description).Editable(true);
              model.Field(c => c.CreatedDateUtc).Editable(false);
              model.Field(c => c.ModifiedDateUtc).Editable(false);
          })
      .Events(events => events.Error("workConfig.gridErrorHandler"))
      .Read(read => read.Action("ReadStatus", "Config", new { area = "Pms" }))
      .Create(update => update.Action("AddStatus", "Config", new { area = "Pms" }))
      .Update(update => update.Action("UpdateStatus", "Config", new { area = "Pms" }))
      .Destroy(update => update.Action("DeleteStatus", "Config", new { area = "Pms" }))
      .PageSize(20)
      ))

6 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 03 Nov 2017, 08:53 AM
Hello, Harsha,

Thank you for the provided code snippet.

The error leads me to believe that the issues lies with the editor of the Description field.

The model in the editor should be an int and you should decorate the Description model field with [UIHint("nameOfTheEditor")]:

@model int?
 
@(Html.Kendo().NumericTextBoxFor(m => m)
      .HtmlAttributes(new { style = "width:100%" })
)

Then, it may also be a good idea to set the default value in the model to 0:

https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-specify-default-property-values-when-new-items-are-created

If these suggestions do not help, please share the model, the Description editor and a sample data item returned from the service with some mocked data so I can see if I can reproduce this behaviour locally.

Look forward to hearing back from you.

Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
HaBo
Top achievements
Rank 1
answered on 07 Nov 2017, 09:22 AM

Hi Alex,
Why do you think Description field is numeric? Its a string. I am guessing you were referring to DisplayOrder?
Here is my model

public class WorkStatus
   {
       [Key]
       public int Id { get; set; }
       [Required]
       public string Name { get; set; }
       public string Description { get; set; }
       [Required]
       [UIHint("Number")]
       public int DisplayOrder { get; set; }
 
       public bool IsDefault { get; set; }
       public Style Style { get; set; }
 
   }


My Number Editor

@model int
 
@(Html.Kendo().NumericTextBoxFor(m => m).Format("0")
      .HtmlAttributes(new { style = "width:100%" })
)

I don't have a UIHint for Description field.

 

 

0
Alex Hajigeorgieva
Telerik team
answered on 08 Nov 2017, 02:54 PM
Hi, Harsha,

Please accept my apology for the confusion. I was misled by the int32 and the error description as well as the presence of a Description property in the model.

Thank you for providing the model declaration.

The only thing which is missing is the Editor template for the boolean value and an editor for the Style class. Could you please provide these as well? If Style does not have an editor, I suggest creating one and decorating the property with the [UIHint] attribute. More about editor templates is available here:

https://docs.telerik.com/aspnet-mvc/helpers/grid/templating/editor-templates 

Look forward to hearing back from you.

Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
HaBo
Top achievements
Rank 1
answered on 08 Nov 2017, 03:50 PM

Boolean Editor: but I am not using this in that UIHint right. How will that makes difference?

@model bool
@Html.CheckBoxFor(x=>Model)

 

To Confirm, problem is not with style property, because I commented the Style Property from Model and tried it is still complaining.

0
HaBo
Top achievements
Rank 1
answered on 08 Nov 2017, 04:38 PM
strangely I renamed Model from WorkStatus to MyStatus and it is working. How crazy it is?
0
Alex Hajigeorgieva
Telerik team
answered on 10 Nov 2017, 09:15 AM
Hello, Harsha,

The Boolean editor template should be something like the below:

@model bool?
 
@(Html.Kendo().CheckBoxFor(m => m))

Perhaps changing the model name somehow went around passing the full model and causing the error.

Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
HaBo
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
HaBo
Top achievements
Rank 1
Share this question
or