Cannot set default value of a Guid column

2 posts, 0 answers
  1. Robert
    Robert avatar
    38 posts
    Member since:
    Feb 2012

    Posted 27 Jun 2012 Link to this post

    I just ran into a situation with the Beta where setting the default value of a Guid column throws an error. Here is some pseudocode:

        public class FloorPlanModel
        {
            [ScaffoldColumn(false)]
            public Guid Id { get; set; }
     
           [ScaffoldColumn(false)]
            public Guid PropertyId { get; set; }
     
            public string Name { get; set; }
     
            public decimal Bedrooms { get; set; }
    }

    And the following Grid code (unnecessary parts omitted):
    @(Html.Kendo().Grid<FloorPlanModel>()
        .Name("floorPlanGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.Name);
            columns.Bound(p => p.Bedrooms).Width(80).EditorTemplateName("Bedrooms");
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .ServerOperation(false)
            .Model(model => {
                                model.Id(p => p.Id);
                                model.Field(p => p.PropertyId).DefaultValue(Model.Id);
                                model.Field(p => p.Bedrooms).DefaultValue(1);
            })
        )
    )
    ...where Model.Id is also a Guid, I get this error:

    Cannot serialize objects of type System.Guid

    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.NotSupportedException: Cannot serialize objects of type System.Guid

    Source Error: 

    Line 254:        </div>
    Line 255:        <div class="tab-pane" id="floorplans">
    Line 256:            @(Html.Kendo().Grid<AdvancedREI.Web.Models.FloorPlanModel>()
    Line 257:                .Name("floorPlanGrid")
    Line 258:                .Columns(columns =>

    Source File: d:\TFSWorking\AdvancedREI\Development\Development\src\AdvancedREI.Web\Views\Properties\_Edit.cshtml    Line: 256 

    Stack Trace: 

    [NotSupportedException: Cannot serialize objects of type System.Guid]
       Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +1180
       Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +354
       Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +354
       Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +354
       Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +354
       Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +354
       Kendo.Mvc.Infrastructure.JavaScriptInitializer.Initialize(String id, String name, IDictionary`2 options) +260
       Kendo.Mvc.UI.Grid`1.WriteInitializationScript(TextWriter writer) +1801
       Kendo.Mvc.UI.ViewComponentBase.WriteHtml(HtmlTextWriter writer) +72
       Kendo.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +1491
       Kendo.Mvc.UI.ViewComponentBase.ToHtmlString() +106
       Kendo.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString() +16
       System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, Object content) +17
       ASP._Page_Views_Properties__Edit_cshtml.Execute() in d:\TFSWorking\AdvancedREI\Development\Development\src\AdvancedREI.Web\Views\Properties\_Edit.cshtml:256
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
       Glimpse.Mvc3.Plumbing.GlimpseView.Render(ViewContext viewContext, TextWriter writer) +258
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
       Castle.Proxies.AsyncControllerActionInvokerProxy.InvokeActionResult_callback(ControllerContext controllerContext, ActionResult actionResult) +21
       Castle.DynamicProxy.AbstractInvocation.Proceed() +72
       Glimpse.Mvc3.Interceptor.InvokeActionResultInterceptor.Intercept(IInvocation invocation) +415
       Castle.DynamicProxy.AbstractInvocation.Proceed() +316
       System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +240
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__4(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +607
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

    I can switch the Model to a string, set the default to Model.Id.ToString(), and then get it back into a Guid on the backend, but that is obviously not ideal.

    Any chance this could get fixed before RTM?

    Thanks!
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 28 Jun 2012 Link to this post

    Hi Robert,

    We are able observe the error you have described and the fix will be available with the next version of the KendoUI for ASP.NET MVC. Meanwhile I have updated your telerik points.

    Regards,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top