Edit is working fine when all entites are in TextBox else giving Error
i am using MVC 3.0 with EF I have Table which contain Identity column with Auto Increment 1. Now i created a View for Edit with only FirstName,LastName and ID will be ReadOnly mode. Now i changed value First Name and Last Name and press submit button then it will gives me an error:
The parameters dictionary contains a null entry for parameter 'colID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32, CAFM.Business.Models.TabMasterViewModel)' in 'CAFM.Web.Controllers.TabMasterController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
If i set ID from RedaOnly to Edit
@Html.DisplayFor(model => model.ID)
to
@Html.EditorFor(model => model.ID)
then it is 开发者_如何学运维working perfectly.
Please provide your valuable suggestions!
Thanks, Imdadhusen
That is quite obvious. When you post edits back to server it doesn't post Id because Id is not in any HTML control - it is just a text. Because of that you cannot create valid entity for saving. You must always post Id back (for example in hidden field) and have some validation that the Id was not changed or that user still have permissions to change the record.
精彩评论