This question is locked. New answers and comments are not allowed.
I'm using Telerik MVC Grid in nopCommerce. If I make a column ReadOnly, when I edit other columns in the row and then click Update, the ReadOnly field goes blank (NULL is stored in DB). My View looks very much like other nop Views that work ok.
@(Html.Telerik().Grid(Model.Records)
.Name("Grid")
.DataKeys(keys => keys.Add(x => x.Id).RouteKey("Id"))
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("RecordsList", ...
.Update("RecordUpdate",...
.Delete("RecordDelete",...
)
.Columns(columns =>
{
columns.Bound(x => x.Kind).Width(40).ReadOnly();
columns.Bound(x => x.Name).Width(100);
columns.Bound(x => x.Description).Width(250);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
}).Width(280);
})
.Editable(x => x.Mode(GridEditMode.InLine))
.EnableCustomBinding(true))
@(Html.Telerik().Grid(Model.Records)
.Name("Grid")
.DataKeys(keys => keys.Add(x => x.Id).RouteKey("Id"))
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("RecordsList", ...
.Update("RecordUpdate",...
.Delete("RecordDelete",...
)
.Columns(columns =>
{
columns.Bound(x => x.Kind).Width(40).ReadOnly();
columns.Bound(x => x.Name).Width(100);
columns.Bound(x => x.Description).Width(250);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
}).Width(280);
})
.Editable(x => x.Mode(GridEditMode.InLine))
.EnableCustomBinding(true))
6 Answers, 1 is accepted
0
iConect Developer - Mike
Top achievements
Rank 1
answered on 17 Nov 2011, 10:59 PM
I'm also having this issue, though I'm marking the Datakey as the readonly column so mine is actually resulting in a crash due to the null value.
0
iConect Developer - Mike
Top achievements
Rank 1
answered on 18 Nov 2011, 01:56 AM
This is the same as this thread over here:
http://www.telerik.com/community/forums/aspnet-mvc/grid/datakey-null-on-ajax-delete.aspx#1880736
Basically it's the name of the key in the controller.
http://www.telerik.com/community/forums/aspnet-mvc/grid/datakey-null-on-ajax-delete.aspx#1880736
Basically it's the name of the key in the controller.
0
Dan
Top achievements
Rank 1
answered on 18 Nov 2011, 08:19 PM
I have the same question regarding ReadOnly columns in a grid. They are not posted to the Update action and therefore get a null value in the DB.
In some cases, I would actually prefer not to even show these ReadOnly columns. I have some data fields that are set when the record is created (i.e. a DateCreated column) and I simply want to keep that value when I do an Update without even showing the column in the grid. In the Telerik ASP.Net AJAX grid you could add these columns to the DataKeys collection so that they would be included in the update parameters. Is there something similar in the MVC grid?
I am new to the MVC environment so any help you can give would be appreciated.
Thanks.
Dan
In some cases, I would actually prefer not to even show these ReadOnly columns. I have some data fields that are set when the record is created (i.e. a DateCreated column) and I simply want to keep that value when I do an Update without even showing the column in the grid. In the Telerik ASP.Net AJAX grid you could add these columns to the DataKeys collection so that they would be included in the update parameters. Is there something similar in the MVC grid?
I am new to the MVC environment so any help you can give would be appreciated.
Thanks.
Dan
0
Hello Dan,
Greetings,
Georgi Tunev
the Telerik team
Yes, you can have more than one datakey set:
Grid().DataKeys(keys =>{ keys.Add(o => o.OrderID); //will be posted as "id" (default MVC route parameter) unless RouteKey is used keys.Add(o => o.CustomerID).RouteKey("CustomerID"); // will be posted as CustomerID});Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Mauro
Top achievements
Rank 1
answered on 30 Nov 2011, 12:47 PM
Georgi Tunev you are responding the trivial question (about add many dataKeys), but the principal question here is how send the value of ReadOnly column. How we can do this?
0
Edward
Top achievements
Rank 1
answered on 14 Dec 2011, 02:56 PM
I solved the problem like this.
Make sure you have a .DataKeys in your grid. Add your readonly field to the DataKeys.
Add a parameter to your action in the controller
id will now be the value of your missing readonly column. Set the value in the model and clear the error.
Make sure you have a .DataKeys in your grid. Add your readonly field to the DataKeys.
.DataKeys(keys => keys.Add(c => c.Key)) Add a parameter to your action in the controller
[GridAction]public ActionResult Save(string id, SystemParameter model)id will now be the value of your missing readonly column. Set the value in the model and clear the error.
//hack to fix the readonly field not being returned in the modelmodel.Key = id;ModelState.Remove("Key"); // hack to fix readonly [required] field error