Javascript error Invalid Char in LostFocus

7 posts, 0 answers
  1. Malcolm
    Malcolm avatar
    29 posts
    Member since:
    Oct 2011

    Posted 08 May 2013 Link to this post

    Dear KendoUI Team!
    In one of my Views I alwas get a javascript error when I leave the focus of the Dropdownlist.

    The error occurs in parseJSON in this line:
    {return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=b.trim(n),n&&k.test(n.replace(S,"@").replace(A,"]").replace(E,"")))?Function("return "+n)():(b.error("Invalid JSON: "+n),t)}

    The Model looks like this:
    [Required]
            [LocalizedDisplayName("Language")]
            public int PreferredLanguageId { get; set; }

    And the cshtml is here:

    div class="type-text">                            
                                @(Html.Kendo().DropDownListFor(m => m.PreferredLanguageId)
                                .Name("PreferredLanguageId")
                                .SelectedIndex(Model.PreferredLanguageId)
                                .BindTo(LeoHelper.GetLanguages())
                                .DataTextField("Text")
                                .DataValueField("Value")
                                )
                            </div>

    Although the javascript Exception is thrown, the value is correctly saved.

    brgds
    Malcolm Howlett
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 10 May 2013 Link to this post

    Hi Malcolm,


    From the provided information it's not clear for us what is the exact reason for this behavior - could you please provide runable project where the issue is reproduced? This would help us pinpoint the exact reason for this behavior.

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Christopher
    Christopher avatar
    4 posts
    Member since:
    Mar 2012

    Posted 06 Jun 2013 Link to this post

    Hi, I have the same problem and I'm very interested to know how to fix this. I cannot provide a runable project but I can give you the following information:

    Here's the JSON object I caught with firebug: [{"salesgeoid":5,"shortname":"ALL"},{"salesgeoid":1,"shortname":"BRA"},{"salesgeoid":3,"shortname":"CHE"},{"salesgeoid":2,"shortname":"FRA"}]

    Here's my view:
    <div class="editor-field">@(Html.Kendo().DropDownListFor(model => model.salesgeoid)
                                        .Name("salesgeo")
                                        .HtmlAttributes(new { style = "width:150px" })
                                        .DataTextField("shortname")
                                        .DataValueField("salesgeoid")
                                        .DataSource(source =>
                                        {
                                            source.Read(read =>
                                            {
                                                read.Action("SalesGeoList", "Profile");
                                            });
                                        }))</div>

    And my controller:
    public JsonResult SalesGeoList()
            {
                return Json(db.SalesGeo.Select(x => new { salesgeoid = x.salesgeoid, shortname = x.shortname }), JsonRequestBehavior.AllowGet);
            }
    Your help would be greatly appreciated.
  5. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 10 Jun 2013 Link to this post

    Hi Christopher,

    I reviewed the provided information, however currently  I'm unable to reproduce the issue on our side. I would suggest to try isolating the problem in a sample project and send it back to us. This would help us pinpoint the exact reason for this behavior. 

    Also I would suggest to remove the Name configuration option as it overrides the name generated from the model property that is bound to the DropDownList. 

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Christopher
    Christopher avatar
    4 posts
    Member since:
    Mar 2012

    Posted 19 Jun 2013 Link to this post

    It'll be hard to isolate the code since the data is stored in a mysql database.

    However I followed your advice and I removed the name attribute, that helped me to access the data in the controller (it wasn't possible before). But the error message still appears in firebug. The message is : "SyntaxError: JSON.parse: unexpected character" and the file is "jquery.min.js (line 3)". Maybe this last information may help you find the source of this problem ?

    Kind regards
  7. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 20 Jun 2013 Link to this post

    Hi Christopher,

     
    Basically the data sent by the controller and the DropDownList configuration looks valid - most probably the issue is related to the scripts included in the project. I would suggest to check for duplicate script includes and make sure that all scripts are the correct versions (for example jQuery should be v1.9.1). For more information about the required scripts I would suggest to check this article

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Christopher
    Christopher avatar
    4 posts
    Member since:
    Mar 2012

    Posted 08 Jul 2013 Link to this post

    Updating the scripts resolved the issue. Thank you for your help.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready