This question is locked. New answers and comments are not allowed.
Hi,
Can someone please help me. I am doing something wrong when using the Grid control. I am using MVC 2 and Q3.
I have a View strongly typed to a Model (Customer). This Customer has a list of CustomerEvents. The View displays information on the Customer and in addition has a Grid of CustomerEvent object. The Grid should support Insert, Edit and Delete.
Here is the View
When cliking the Edit button I get an error in Details of the CustomerController because the CustomerEvent Id is passed in and not the Customer.Id
Please help me as these problems are showstoppers.
Best regards
PÃ¥l Eilertsen
Can someone please help me. I am doing something wrong when using the Grid control. I am using MVC 2 and Q3.
I have a View strongly typed to a Model (Customer). This Customer has a list of CustomerEvents. The View displays information on the Customer and in addition has a Grid of CustomerEvent object. The Grid should support Insert, Edit and Delete.
Here is the View
<%: Html.Telerik().Grid<CustomerEvent>(Model.CustomerEvents)I have managed to get Insert to work with this code, but when I use Edit or Delete it al goes wrong.
.Name("CustomerEvents")
.DataKeys(keys => keys.Add(ce => ce.ID))
.ToolBar(commands => commands.Insert())
.DataBinding(databinding => databinding.Server()
.Select("Details", "Customer", new {id = Model.ID})
.Insert("Create", "CustomerEvent", new { id = Model.ID })
.Update("Save", "CustomerEvent")
.Delete("Delete", "CustomerEvent"))
.Columns(columns =>
{
columns.Bound(p => p.Created).Width(115).Format("{0:d}");
columns.Bound(p => p.Action).Width(130).Title("Type");
columns.Bound(p => p.Comment).Width(150).Title("Kommentar");
columns.Bound(p => p.Officer.FullName).Width(130).Title("RÃ¥dgiver");
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
}).Width(180).Title("");
})
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Pageable(paging => paging.PageSize(5))
.Sortable()
.Filterable()
%>
When cliking the Edit button I get an error in Details of the CustomerController because the CustomerEvent Id is passed in and not the Customer.Id
//When clicking the Delete button I get a similar error. The Delete action of the CustomerEventController has the Customer.Id in the id parameter not the actual CustomerEvent Id.
// GET: /Customer/Details/5
public ActionResult Details(int id)
{
var customer = db.Customers.Single(c => c.ID == id);
return View(customer);
}
[HttpPost]I am obiviously doing something wrong here. I have a similar problem with another View where the View is strongly typed to a ViewModel object.
public ActionResult Delete(int id, FormCollection collection)
{
var customerEvent = db.CustomerEvents.Single(ce => ce.ID == id);
int? customerId = customerEvent.CustomerId;
db.DeleteObject(customerEvent);
db.SaveChanges();
return RedirectToAction("Details/" + customerId, "Customer");
}
Please help me as these problems are showstoppers.
Best regards
PÃ¥l Eilertsen