Custom Editor throwing js error after "Add New Record" clicked.

3 posts, 0 answers
  1. Dave
    Dave avatar
    2 posts
    Member since:
    May 2016

    Posted 04 Aug Link to this post

    "Unhandled exception at line 1362, column 66 in Function code

    0x800a1391 - JavaScript runtime error: 'ParameterSet' is undefined."

    I'm going to include as little code as possible to demonstrate what things look like:

    >>View <<

    @(Html.Kendo().Grid<Web.Models.ModelingJobViewModel>()
    ...
     columns.Bound(c => c.ParameterSet).ClientTemplate("#=ParameterSet.Name#");
    ...

    >>View Model <<

    public class ModelingJobViewModel
    ...
       [UIHint("ParameterSetEditor")]
       public JobParameterSetViewModel ParameterSet {get; set;}
    ...

    >> "Property" view model <<

    public class JobParameterSetViewModel
    ...
       public int Id {get; set;}
       public string Name {get; set;}
    ...

    >> Controller <<

    ...
      public ActionResult Index()
    ...
       ViewData["parameterSets"] = repo.SelectAll().Select(e=>new DropdownListItem() { Name = e.name, Id = e.Id}).OrderBy(e => e.Name);
    ...

    >> Custom Editor (ParameterSetEditor) <<
    @model Web.Models.ModelingJobViewModel

    @(Html.Kendo().DropDownListFor(m => m)
        //.Name("ParameterSet")
        .DataValueField("Id")
        .DataTextField("Name")
        .BindTo((System.Collections.IEnumerable)ViewData["parameterSets"])
    )

    The initial view and the edit action buttons work fine.  But when "Add" is clicked, I get the error listed above.

    It's probably something stupid, but I've spun my wheels long enough and need to throw this out into the forum to see if anyone has an answer. Help!

    Thanks in advance!

     

  2. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    347 posts

    Posted 08 Aug Link to this post

    Hello Dave,

    You can check out the following Grid online demo showing editing a field with a DropDownList custom editor, and apply the necessary adjustments to your implementation:

    http://demos.telerik.com/aspnet-mvc/grid/editing-custom

    The demo, along with its corresponding custom editor configuration, controller, and actions, is also available in the sample application, coming with your installation package:

    http://docs.telerik.com/kendo-ui/aspnet-mvc/introduction#sample-application

    Please make sure to provide a default value for the ParameterSet field (equivalent to the Category field from the example).

    I hope this helps.

    Regards,
    Dimiter Topalov
    Telerik by Progress
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
  3. Kendo UI is VS 2017 Ready
  4. Dave
    Dave avatar
    2 posts
    Member since:
    May 2016

    Posted 08 Aug in reply to Dimiter Topalov Link to this post

    The lack of a default value for the field was the issue.  Added it, plus made sure the view model that was loaded in the list of possible values and the default matched the model used by the editor. Boom. Works.

    And...yeah...that was kinda stupid.  I should have made the connection with the Add New event and the lack of a default.

    Thanks for the assist!

Back to Top