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

Several Problems/Questions with MVVM in Kendo

1 Answer 129 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Walt
Top achievements
Rank 1
Walt asked on 02 Nov 2012, 04:46 PM
I've just been recently looking into KendUI as a solution for my company and in tests I have run into a few problems and have not found anything useful in your documentation.

The questions:

Can you create a model outside of the view model and reference it from the view model? 
In other frameworks such as KnockoutJS you can create your view model and models independently of each other. I don't believe I saw a way to do this in your documentation

How do you set the option a select defaults to?
I noticed that there is an option in the drop down list widget for and option named "optionLabel" that creates a default option in your drop down list. I tried using what I assumed was your method of specifying it in the MVVM framework using "data-option-label" but that only added an option to the select list and didn't display it by default. Does this have to be done using the value binding in order to work correctly?

How do you specify calculated fields in select boxes?
I saw in your documentation that you used 
<div data-bind="text: person.lowerCaseName"></div>
to call a function that returns a lowercase string but if I do that on a select I just get the string representation of the function I declared. If I added parenthesis to the end then the correct value was displayed in the select box but that broke the code if I used an optionLabel, which leads into my next question.

How do you use calculated values in situations where you also use the "optionLabel?"
I tried using both on a select but exceptions were thrown because it was trying to find the calculation function on the option label which is only a string object.

1 Answer, 1 is accepted

Sort by
0
Lynn
Top achievements
Rank 1
answered on 29 Nov 2012, 06:36 PM
Did you get an answer for your question 'How do you set the option a select defaults to''? I can get it to work if I make my int nullable. 

In the model:
int myId - Kendo dropdown does not select my option label by default
int? myId - Kendo dropdown does select my option label by default

In .cshtml:
 @(Html.Kendo().DropDownListFor(m => m.myId )
                      .Name("MyId")
                      .OptionLabel("Select value...")

Obviously I don't want to have to change my model just so the UI can correctly set the dropdown, but it is a work-around if you're desperate. Please post if you do get a better solution.

Tags
MVVM
Asked by
Walt
Top achievements
Rank 1
Answers by
Lynn
Top achievements
Rank 1
Share this question
or