How Kendo Grid Display Values From MVC Model

3 posts, 0 answers
  1. Diga
    Diga avatar
    4 posts
    Member since:
    May 2015

    Posted 04 Jun 2015 Link to this post

    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. Rosen
    Rosen avatar
    3253 posts

    Posted 08 Jun 2015 Link to this post

    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.

    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
  3. Diga
    Diga avatar
    4 posts
    Member since:
    May 2015

    Posted 08 Jun 2015 in reply to Rosen Link to this post

    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!
Back to Top