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

How Kendo Grid Display Values From MVC Model

2 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Diga
Top achievements
Rank 1
Diga asked on 04 Jun 2015, 09:16 AM

Not the best title, because I don't know what title to give a good title for this issue.

Basically, I am trying to build a Grid with the ASP.NET MVC wrapper for a MVC model I created. All is fine. In fact, I am pleasantly surprised that Kendo is able to display data properly when I set `<DisplayFormat(DataFormatString:="{0:N0}")>` to one of the fields in my model. (It gives commas every 3 digits from the least significant digits i.e. 12345 => 12,345 etc). However, when I added the annotation `NullDisplayText:="0"`, the grid still leaves the cell blank instead of displaying "0" on the cell where the value is NULL.

So my question is that, why the behaviour is as such? I thought Kendo called `@Html.DisplayFor(Function(s) s.Property)` somewhere in the background but apparently this is not the case (since the annotation for `NullDisplayText` is not acknowledged).

Also, naturally, the next question is, how do I get the behaviour I am expecting? I would guess you would suggest me to use Client Template as suggested in this post, but I am hoping that I have done something wrong somewhere and that it can be placed all in one location just like the `DataFormatString` annotation.

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 08 Jun 2015, 07:27 AM

Hello Diga,

Indeed, the DisplayFor will be used if server-side binding/rendering is used and the Format setting of the column is not set. However, when using AJAX binding, it is not possible (nor we have such intention) to replicate the DisplayFor logic in JavaScript as this is how the Grid is constructed in this case. Therefore, I'm afraid that you will need to use the ClientTemplate in order to customize the content of the cell when there is no value.

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Diga
Top achievements
Rank 1
answered on 08 Jun 2015, 08:21 AM
Ah I see, I understand. Anyway I have decided to use a DTO wrapper for the Ajax binding as a workaround. Thank you for the reply!
Tags
Grid
Asked by
Diga
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Diga
Top achievements
Rank 1
Share this question
or