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

Inline edit in grid succeeds, Popup edit fails

8 Answers 255 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Masoud
Top achievements
Rank 1
Masoud asked on 04 Apr 2013, 02:52 PM
Hello!

I have the following Model

public class Mandant
{
     public Guid Id { get; set; }   
    public string Name { get; set; }
    public DateTime ErzeugtAm { get; set; }
    public DateTime AktualisiertAm { get; set; }
    public string ErzeugtVon { get; set; }
    public string StrasenAdresse { get; set; }
    public string Postfach { get; set; }
    public string Plz { get; set; }
    public string Stadt { get; set; }
    public string Staat { get; set; }
}

A Grid is constructed to list and edit the Mandant Model

<%=html.Kendo().Grid<MandantEntity>()
.Name("Mandanten")
.ToolBar(toolbar => toolbar.Create())
.Pageable(pageable => pageable.ButtonCount(5))
.Sortable(sortable => sortable.AllowUnsort(true).SortMode(GridSortMode.SingleColumn))
.Filterable()
.Editable(editable => editable.Mode(
GridEditMode.InLine))
.DataSource(dataSource => dataSource.Ajax()
.PageSize(5)
.Read(read => read.Action(
"Read", "Mandant"))
.Update(update => update.Action("Update", "Mandant"))
.Create(create => create.Action("Create", "Mandant"))
.Model(model => 
    {
        model.Id(p => p.Id); 
        model.Field(field => field.Id).DefaultValue(Guid.NewGuid()); 
        model.Field(field => field.ErzeugtAm).DefaultValue(DateTime.MinValue);
        model.Field(field => field.AktualisiertAm).DefaultValue(DateTime.MinValue);
        model.Field(field => field.ErzeugtVon).DefaultValue(Guid.NewGuid());
        model.Field(field => field.AktualisiertVon).DefaultValue(Guid.NewGuid());
    }))    
.Columns(columns =>
{
    columns.Bound(o => o.Name).Width(180);
    columns.Bound(o => o.StrassenAdresse).Width(180);
    columns.Bound(o => o.Postfach).Width(50);
    columns.Bound(o => o.Plz).Width(60);
    columns.Bound(o => o.Stadt).Width(60);
    columns.Bound(o => o.Staat).Width(60);
    columns.Command(command => command.Edit()).Width(200);
})
    %>

As above, the code works great.  I can load the view, edit existing elements, and create new ones.

When I change the Mode to GridEditMode.PopUp, I can no longer load the view. I get instead the following error. 
I would really appreciate your help on this!



 

The model item passed into the dictionary is of type 'System.Guid', but this dictionary requires a model item of type 'System.String'.
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 'System.Guid', but this dictionary requires a model item of type 'System.String'.
Source Error:

Line 7:  
Line 8:  <asp:Content ID="indexFeatured" ContentPlaceHolderID="FeaturedContent" runat="server">
Line 9:      <%= Html.Kendo().Grid<MandantEntity>()
Line 10:     .Name("Mandanten")
Line 11:     .ToolBar(toolbar => toolbar.Create())   // zeigt den Button für New oben    

Source File: c:\Abakus\trunk\src\AbaScore\AbaScore\Views\Mandant\Index.aspx    Line: 9
Stack Trace:

[InvalidOperationException: The model item passed into the dictionary is of type 'System.Guid', but this dictionary requires a model item of type 'System.String'.]
   System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +584415
   System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +371
   System.Web.Mvc.ViewUserControl`1.SetViewData(ViewDataDictionary viewData) +48
   System.Web.Mvc.WebFormView.RenderViewUserControl(ViewContext context, ViewUserControl control) +63
   System.Web.Mvc.WebFormView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +78
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   Castle.Proxies.Invocations.IView_Render.InvokeMethodOnTarget() +118
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Glimpse.Core.Extensibility.CastleInvocationToAlternateMethodContextAdapter.Proceed() +11
   Glimpse.Core.Extensibility.ExecutionTimer.Time(Action action) +76
   Glimpse.Core.Extensions.AlternateMethodContextExtensions.TryProceedWithTimer(IAlternateMethodContext context, TimerResult& timerResult) +135
   Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context) +25
   Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation) +84
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.IViewProxy.Render(ViewContext viewContext, TextWriter writer) +214
   System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +579
   System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1002
   System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +66
   System.Web.Mvc.Html.DefaultEditorTemplates.ObjectTemplate(HtmlHelper html, TemplateHelperDelegate templateHelper) +554
   System.Web.Mvc.Html.DefaultEditorTemplates.ObjectTemplate(HtmlHelper html) +48
   System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +709
   System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1002
   System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +66
   System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper html, Object additionalViewData) +51
   Kendo.Mvc.UI.Html.GridHtmlHelper`1.EditorForModel(Object dataItem, String templateName, IEnumerable`1 foreignKeyData, Object additionalViewData) +161
   Kendo.Mvc.UI.Grid`1.InitializeEditors() +747
   Kendo.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +474
   Kendo.Mvc.UI.WidgetBase.ToHtmlString() +81
   Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString() +22
   Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToString() +5
   System.Web.HttpWriter.Write(Object obj) +24
   System.Web.Mvc.SwitchWriter.Write(Object value) +13
   System.Web.UI.HtmlTextWriter.Write(Object value) +31
   ASP.views_mandant_index_aspx.__RenderindexFeatured(HtmlTextWriter __w, Control parameterContainer) in c:\Abakus\trunk\src\AbaScore\AbaScore\Views\Mandant\Index.aspx:9
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +268
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Abakus\trunk\src\AbaScore\AbaScore\Views\Shared\Site.Master:36
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +268
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +41
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1386

8 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 05 Apr 2013, 03:14 PM
Hi Klaus,


From the provided information it seems that you are passing "Guid" object as default value for properties of type "string" which is invalid configuration. I would suggest to use the ToString method to convert the "Guid" object to the correct type:

//convert the Guid to string
model.Field(field => field.AktualisiertVon).DefaultValue(Guid.NewGuid().ToString());


Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Masoud
Top achievements
Rank 1
answered on 05 Apr 2013, 05:14 PM
Hi Vladimir,

I made a mistake copying the code.  ErzeugtVon as well as AktualisiertVon are both Guids. My bad.
I have created a test project that reproduces the issue.  The zip is 20 MB large.  I am unable to attach it to my reply, how can I send you the test project?

Thank you very much for your help!
0
Accepted
Vladimir Iliev
Telerik team
answered on 08 Apr 2013, 06:44 AM
Hi Klaus,

 
There are several ways you can proceed:

  • Open a new support thread - support threads have 20mb limit for file uploads
  • Upload the project to some public FTP and provide the download link here
  • Remove all unrelated widgets, packages and files from the project to reduce it's size and attach it to current thread

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Masoud
Top achievements
Rank 1
answered on 08 Apr 2013, 08:57 AM
Hi Vladimir,

I have opened a support thread untder http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=679726

Best regards
0
Clark Roberts
Top achievements
Rank 1
answered on 25 Apr 2013, 04:02 PM
I'm having the same problem. Inline edit succeeds.  The following configuration throws this error when loading.
The model item passed into the dictionary is of type 'System.Guid', but this dictionary requires a model item of type 'System.String'.

@(Html.Kendo().Grid<Canopy.Admin.Api.Models.CanContext>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ContextUid).Visible(false);
columns.Bound(p => p.Version);
columns.Bound(p => p.StatusId).Title("Status");
columns.Bound(p => p.Value);
columns.Bound(p => p.Description);
columns.Bound(p => p.Title);
columns.Command(command => { command.Edit(); command.Destroy(); }).Title("Action").Width(200);
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ContextUid))
.Create(update => update.Action("Create", "Context"))
.Read(read => read.Action("List", "Context"))
.Update(update => update.Action("Update", "Context"))
.Destroy(update => update.Action("Delete", "Context"))
)
)
0
Vladimir Iliev
Telerik team
answered on 26 Apr 2013, 05:33 AM
Hi Clark,

 
After further investigation it seems that the issue comes from the default EditorTemplate for this field String.cshtml) which accepts model of type String. I would suggest to modify the String editor template to accept model of type object instead:

@model object
 
@Html.TextBoxFor(model => model, new {@class="k-textbox" })

 Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Clark Roberts
Top achievements
Rank 1
answered on 26 Apr 2013, 03:35 PM
That solution doesn't work for me. It throws a different error on
@Html.TextBoxFor(model => model, new { @class = "k-textbox" })
ArgumentException was unhandled by user code
Value cannont be null or empty

Actually what I really want to have is a good simple example of Kendo Grid actions opening a Kendo Window and passing the ID for the selected row to the window so it shows the correct data for the selected row. The follow code is from my Index.cshtml. I have a button on grid for chosing the row and opening the window. Just can't make the link to pass the Id for the dataitem to the window. And the .LoadContentFrom(Url.Action("Details", "Context", new { ID = ViewData["ID"] })) doesn't trigger.

@(Html.Kendo().Grid<Canopy.Admin.Api.Models.CanContext>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ContextUid).Visible(false);
columns.Bound(p => p.Version).Width(80);
columns.Bound(p => p.StatusId).Title("Status").Width(80);
columns.Bound(p => p.Value).Width(100);
columns.Bound(p => p.Description).Width(200);
columns.Bound(p => p.Title).Width(200);
columns.Command(command => { command.Edit(); command.Destroy(); command.Custom("ViewDetails").Click("showDetails"); }).Title("Action").Width(170);
})
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single))
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.Events(events => events.Change("onChange"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ContextUid))
.Create(update => update.Action("Create", "Context"))
.Read(read => read.Action("List", "Context"))
.Update(update => update.Action("Update", "Context"))
.Destroy(update => update.Action("Delete", "Context"))
)
)
@(Html.Kendo().Window().Name("Details")
.Width(630)
.Visible(false)
.Height(315)
.Draggable()
.Resizable()
.Title("Context Details")
.Content("loading info...")
.Actions(actions => actions.Refresh().Maximize().Close())
.LoadContentFrom(Url.Action("Details", "Context", new { ID = ViewData["ID"] }))
)

<script type="text/javascript">
function showDetails(e) {
e.preventDefault();
var entityGrid = $("#Grid").data("kendoGrid");
var selectedItem = entityGrid.dataItem(entityGrid.select());
var id = selectedItem.id;
var wnd = $("#Details").data("kendoWindow");

//wnd.content(detailsTemplate(dataItem));
wnd.center().open();
}
</script>
0
Vladimir Iliev
Telerik team
answered on 30 Apr 2013, 10:25 AM
Hi Clark,


Your last question is not related to the original topic of this support conversation, so please submit a new support ticket for it. In this way you can be sure that your query will reach the corresponding staff member in time and will be answered faster and accurately.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Masoud
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Masoud
Top achievements
Rank 1
Clark Roberts
Top achievements
Rank 1
Share this question
or