开发者

Telerik Grid MVC2 Insert child records in nested grid

The Master grid is Customers and the Detail grid is a Customers Orders. Using the EditorTem开发者_运维技巧plate, I have the Model working just fine for updates but when it comes to inserting new records I'm at a loss.

The CustomerId is not being passed, in any way that I can see, to the UserControl. So new Orders are being created with a CustomerId of 0.

The Orders table has a unique key on CustomerId and Order # and OrdersId is primary. I need to create a new Customer Order record entering the Order # but the Customer # needs to be provided to the form.

I am obviously missing something and certainly don't see any help on the Telerik site when it comes to their grid and MVC.

Any help would be greatly appreciated!


From my point of view, allowing the users to enter the key field value for the new items is not a good practice because this is prone to error (the keys may not be unique or valid in the context of the column type). What I chose for my grids is to have the key field auto-increment or generate the key values for new rows by myself to ensure there are no repetitions.


The record id is always returned as "id" and must be coded that way.

[GridAction]
public ActionResult _SaveMasterTable(int id) {
    using (DataContext dc = new DataContext()) {
        MasterTable model = dc.MasterTables.SingleOrDefault(
            e => (e.MasterId == id)
        );e

In the case above the Master record would be updated. For child records, the record id returned is the masters... allowing you to insert the new record with the master id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜