ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Grid Inline Edit - The Field "ID" is required
Title:
B
I
{code}
?
Hi O! I'm really stuck in the moment. I've already had this issue but I dont know anymore how I've solved it. My Controller: private static object MapToGridModel(Users o) { return new { o.Id, UserId = string.Format("{0}\\{1}", o.UserDomain, o.UserId), IsAdmin = ((o.IsAdmin!=null) && (o.IsAdmin==true)) ? "Yes" : "", IsAdminChecked = ((o.IsAdmin != null) && (o.IsAdmin == true)) ? "checked" : "" }; } My View @(Html.Awe().Grid("UsersGrid") .Mod(o => o.PageInfo().PageSize().InlineEdit(Url.Action("Create", "UsersGrid"), Url.Action("Edit", "UsersGrid"))) .Url(Url.Action("GetItems", "UsersGrid")) .Parent("txtSearch", "search") .Resizable(true) .Groupable(false) .Sortable(true) .Height(0) .Columns( new Column { Bind = "Id", Hidden = true }.Mod(o => o.InlineId("Id", "Id")), new Column { Bind = "UserId", Header = "Domain\\User Id", Width = 260 }.Mod(o => o.Inline(Html.Awe().TextBox("UserId"))), new Column { Bind = "IsAdmin", Header = "Admin", Width = 160 }.Mod(o => o.InlineBool(cssClass: "btoggle")), new Column { ClientFormat = GridUtils.InlineEditFormat(), Width = 60 }, new Column { ClientFormatFunc = "getDeleteItem('deleteUsersGrid', 'Id')", Width = 70 } ) ) When I perform inline create, I get validation error "Field 'ID' is required". But my Id Field is DB Identity. The same code works with other table (but there the Id field calls OSId)
Save Changes
Cancel
TT Tom
asked at 21 Dec 2015
looks like a server side error, so you should put a breakpoint on the Create Post action and investigate, see what is missing/wrong
at 21 Dec 2015
Omu
When i create a new element the Id is empty, because it will be generated by the database on insert. So on Post the model validation says the Id is empty and required. I could use an aditional ViewModel and define Id as nullable (int?), this could work. But as i mentioned before, almost the same code works with another table. There is also an Identity Id called appId and this works - really strange
at 21 Dec 2015
TT Tom
show me your viewmodel and how you call create here, and on the other grid where it works
at 21 Dec 2015
Omu
OK, I try to make a sample but for now I've discovered, that when I use differnet name for Id column, it works. I've renamed my Id Column (Primary Key, Identity) to SNId in the Database, generated the model again and used it in grid like this new Column { Bind = "SNId", Hidden = true }.Mod(o => o.InlineId("SNId", "Id")), and changed all Id refrences in Controller to SNId. Now it works perfectly, but this is not really my preferred solution
at 21 Dec 2015
TT Tom
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK