Hello,
I have a grid setup and working with read (paging, sorting etc.) and create actions. I'm having trouble with the update. Basically, the ID does not come through with the rest of the request. I can see it in the browser's network tab, so it is being sent, but when the controller action is finally executed, it is missing from the parameter object.
View Index.cshtml
ConciergeModel.cs
And the controller action in ConciergeController.cs
Here is an example request, taken from Firebug (FF 17.0)
So you can see that the ID should be 2, but it is zero, which causes the update operation to fail - the dataservice can't run the update query without the ID.
At one point, I had the ID with a private setter and marked with a [ReadOnly(true)] attribute, but as you can see, I removed that and the problem persisted.
I have a grid setup and working with read (paging, sorting etc.) and create actions. I'm having trouble with the update. Basically, the ID does not come through with the rest of the request. I can see it in the browser's network tab, so it is being sent, but when the controller action is finally executed, it is missing from the parameter object.
View Index.cshtml
@
using
Kendo.Mvc.UI
@
using
Mvc.Models
@model IEnumerable<ConciergeModel>
@{
ViewBag.Title =
"Manage Live-Connect Concierge List"
;
Layout =
"~/Views/Shared/_Kendo.cshtml"
;
}
<h2>@ViewBag.Title</h2>
<h3>Server Side Initialization</h3>
@{
try
{
@(Html.Kendo().Grid(Model)
.Name(
"Concierge"
)
.Columns(columns =>
{
columns.Bound(c => c.ConciergeId).Groupable(
false
).Width(40);
columns.Bound(c => c.ConciergeName).Width(240);
columns.Bound(c => c.ConciergeEmail).Width(480);
columns.Command(command => command.Edit());
})
.ToolBar(toolbar =>
{
toolbar.Create();
})
.Editable(editable => editable.Mode(GridEditMode.Inline))
.Pageable()
.Sortable()
.Scrollable()
.DataSource( dataSource => dataSource
.Ajax()
.Model(model => model.Id(c => c.ConciergeId))
.Create(create => create.Action(
"ConciergeCreate"
,
"Concierge"
))
.Read(read => read.Action(
"ConciergeRead"
,
"Concierge"
))
.Update(update => update.Action(
"ConciergeUpdate"
,
"Concierge"
))
))
}
catch
(Exception e)
{
@Html.Raw(
"<pre>"
+ e +
"</pre>"
);
}
}
using
System.ComponentModel;
using
System.ComponentModel.DataAnnotations;
namespace
Mvc.Models
{
public
class
ConciergeModel
{
public
ConciergeModel() { }
[Required]
[DisplayName(
"ID"
)]
public
long
ConciergeId {
get
;
set
; }
[Required]
[DisplayName(
"Name"
)]
[DataType(DataType.Text)]
public
string
ConciergeName {
get
;
set
; }
[Required]
[DisplayName(
"Email Address"
)]
[DataType(DataType.EmailAddress)]
public
string
ConciergeEmail {
get
;
set
; }
}
}
// POST: /mvc/{admin-id}/Concierge/ConciergeUpdate
[AcceptVerbs(HttpVerbs.Post)]
public
JsonResult ConciergeUpdate([DataSourceRequest] DataSourceRequest request,
ConciergeModel concierge)
{
if
(concierge !=
null
&& ModelState.IsValid)
{
// At this point, concierge.ConciergeId is zero
concierge.Update(_lccConciergeService);
}
return
Json(
new
[] { concierge }.ToDataSourceResult(request, ModelState));
}
Response Headers
Cache-Control | private |
Content-Length | 0 |
Date | Sun, 23 Dec 2012 23:19:15 GMT |
Persistent-Auth | true |
Server | Microsoft-IIS/8.0 |
X-AspNet-Version | 4.0.30319 |
X-AspNetMvc-Version | 3.0 |
X-Powered-By | ASP.NET |
X-SourceFiles | =?UTF-8?B?QzpcTGVhZE1hc3RlclxMYXRlc3RccGxhdGZvcm1cTGVhZE1hc3RlclBsYXRmb3JtXEF3bC5MZWFkTWFzdGVyLk12Y1wxMjNcQ29uY2llcmdlc1xDb25jaWVyZ2VVcGRhdGU =?= |
Request Headersview source
Accept | */* |
Accept-Encoding | gzip, deflate |
Accept-Language | en-US,en;q=0.5 |
Cache-Control | no-cache |
Connection | keep-alive |
Content-Length | 110 |
Content-Type | application/x-www-form-urlencoded; charset=UTF-8 |
Cookie | ASP.NET_SessionId=4ff34okn0jkkwqi3k0qswb4l |
Host | localhost:7171 |
Pragma | no-cache |
Referer | http://localhost:7171/mvc/123/Concierges/ |
User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0 |
X-Requested-With | XMLHttpRequest |
Parametersapplication/x-www-form-urlencoded
|
|
ConciergeEmail | jimbob@allwebleadstransferportal.com |
ConciergeId | 2 |
ConciergeName | Jim Bob |
filter | |
group | |
sort |
Source
|
|
sort=&group=&filter=&ConciergeId=2&ConciergeName=Jim+Bob&ConciergeEmail=jimbob%40allwebleadstransferportal .com |
So you can see that the ID should be 2, but it is zero, which causes the update operation to fail - the dataservice can't run the update query without the ID.
At one point, I had the ID with a private setter and marked with a [ReadOnly(true)] attribute, but as you can see, I removed that and the problem persisted.