I have tried to set a default value for a number column like this:
pCs.ColumnSetting().ColumnKey("StyleKey").DefaultValue(@Model.Pk); // doesn't works. pCs.ColumnSetting().ColumnKey("StyleKey").DefaultValue(Model.Pk); // doesn't works either.
but that produce error. The only thing that works is:
pCs.ColumnSetting().ColumnKey("StyleKey").DefaultValue(@Model.Pk.ToString()); // this works but I want a number, not string.
but StyleKey is number and that renders a string.
How to set a default number value using razor?
OK Martin, thank you. It would be good if you change the MVC helper to accept numbers. Let me know if you decide to do it so I can update my code.
Hello Luis,
Documentation which you're looking at is for the JavaScript API. The DefaultValue in the MVC helper wrapper currently accepts string, that's why you have to cast your values to string in order to make it work. We will investigate whether we can improve the DefaultValue in the MVC helper wrapper to accept an object.
Hope this helps,Martin PavlovInfragistics, Inc.
StyleKey and @Model.Pk are both numeric, the problem is that int type value is not a valid argument for DefaultValue, look at the picture. The documentation says that DefaultValue "can be string, number, Date or boolean." I don't have any problem casting string into int with parseInt() when reading the cell value to assign it, for example, to a numeric type var, I am just curious why I can't pass an int to DefaultValue using Razor.
What prevents you from casting it to string?
Best regards,Martin PavlovInfragistics, Inc.
Hi Martin. In my viewmodel the column StyleKey is a number but I don't know how to pass it using Razor.