4

グリッドはサーバーバインディングのb/cをロードします。他のすべてのアクションは、間違ったルートに投稿するか、デフォルトのアクションに投稿します。投稿を/ EditOrderアクションに挿入します。投稿を次のアドレスに編集します: http:// localhost:20588 / Orders / EditOrder / sdsddd?OrderID = 2&CustomerID = 1&ItemsInOrderGrid- コントローラーのAJAXセクション内のブレークポイント以外には意味のないmode=edit (sdsdddはItemID)に到達します。私が間違っていることは何ですか?

ありがとう、ダニ

ビューコードは次のとおりです。

 <%=
                Html.Telerik().Grid(Model.ItemsInOrderList)
                    .Name("ItemsInOrderGrid")
                                    .DataKeys(dataKeys =>
                                    {
                                        dataKeys.Add(e => e.OrderID);
                                        dataKeys.Add(e => e.ItemID);
                                    })
                    .ToolBar(commands => commands.Insert())
                    .DataBinding(dataBinding =>
                        dataBinding.Ajax()    //Ajax binding
                .Select("ItemsGridAjax", "Orders", new {OrderID = Model.order.OrderID})
                .Insert("InsertItemsGridAjax", "Orders", new {OrderID = Model.order.OrderID})
                .Update("UpdateItemsGridAjax", "Orders")
                .Delete("DeleteItemsGridAjax", "Orders"))
                    //.BindTo(Model.ItemsInOrderList)
                    .Columns(c =>
                        {
                            c.Bound(o => o.ItemID);
                            c.Bound(o => o.OrderID).Column.Visible = false;
                            c.Bound(o => o.ItemDescription);
                            c.Bound(o => o.NumOfItems);
                            c.Bound(o => o.CostOfItem);
                            c.Bound(o => o.TotalCost);
                            c.Bound(o => o.SupplyDate);
                            c.Command(commands =>
                                {
                                    commands.Edit();
                                    commands.Delete();
                                }).Width(200);
                        })

            %>

コントローラのコードは次のとおりです。

[GridAction]    
public ActionResult ItemsGridAjax(int OrderID)       
{          
return View(ordersRepository.GetOrderItemsTK(OrderID));     
}

[HttpPost]
        [GridAction]
        public ActionResult InsertItemdGridAjax(int OrderID)
        {
            //Create a new instance of the EditableCustomer class.
            ItemsInOrder newItem = ItemsInOrder.CreateItemsInOrder(OrderID, "");
            newItem.OrderID = OrderID;

            //Perform model binding (fill the customer properties and validate it).
            if (TryUpdateModel(newItem))
            {
                //The model is valid - insert the customer.
                bool res = ordersRepository.InsertItemToOrder(OrderID, newItem);
            }

            //Rebind the grid
            return View(ordersRepository.GetOrderItemsTK(OrderID));
        }



[HttpPost]
  [GridAction]
  public ActionResult UpdateItemsGridAjax(int OrderID, string ItemID)
  {
      //Find a customer whose CustomerID is equal to the id action parameter
      ItemsInOrder item = ordersRepository.FindItemByID(OrderID,ItemID);

      if (item != null)
      {
          //Perform model binding (fill the customer properties and validate it).
          if (TryUpdateModel(item))
          {
              //The model is valid - update the customer and redisplay the grid.
              ordersRepository.UpdateItem(item);
          }
      }
      // TODO: Add try-catch with error reporting.
      //Rebind the grid
      return View(ordersRepository.GetOrderItemsTK(OrderID));
  }

[HttpPost]
        [GridAction]
        public ActionResult DeleteItemsGridAjax(int OrderID, string ItemID)
        {
            //Find the customer with the specified id
            ItemsInOrder item = ordersRepository.FindItemByID(OrderID, ItemID);

            if (item != null)
            {
                //Delete the customer
                ordersRepository.DeleteItem(item);
            }

            //Rebind the grid
            return View(ordersRepository.GetOrderItemsTK(OrderID));
        }
4

2 に答える 2

1

これらのAjaxアクションに属性が必要かどうかはわかりません[HttpPost](私はそれで十分だと思います[GridAction])。おそらくそれらを削除して、問題が解決するかどうかを確認してください。

それがうまくいかなかった場合は、GridModel次のようにアクションでaを返してみてください。

        [GridAction]
        public ActionResult InsertItemdGridAjax(int OrderID)
        {
            //Omitted Code

           return View(new GridModel(ordersRepository.GetOrderItemsTK(OrderID)));
        }

次のような構文を使用することもできます(私が思うにGridModeltotal

        [GridAction]
        public ActionResult InsertItemdGridAjax(int OrderID)
        {
            //Omitted Code

            //Get List of Order Items
            List<OrderItem> list = ordersRepository.GetOrderItemsTK(OrderID));

            return View(new GridModel
            {
                Data = list,
                Total = list.Count
            });
        }
于 2011-01-12T14:34:12.367 に答える
1

Aも同じ問題を抱えていましたが、MVC3では

解決策は、適切な* .jsスクリプトをプロジェクトに追加することでした。これ@(Html.Telerik().ScriptRegistrar().jQuery(false))を参照して、_Layout.cshtmlファイルの最後に 追加してください。

その後、ルーティングはうまくいきます!

于 2011-12-18T22:14:25.713 に答える