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

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

2 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 04 Aug 2016, 09:57 PM

"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 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 08 Aug 2016, 01:09 PM
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.
0
Dave
Top achievements
Rank 1
answered on 08 Aug 2016, 03:07 PM

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!

Tags
Grid
Asked by
Dave
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Dave
Top achievements
Rank 1
Share this question
or