gpt4 book ai didi

asp.net-mvc-2 - Telerik Grid for ASP.NET MVC2 Ajax 绑定(bind)不起作用/路由到错误的操作

转载 作者:行者123 更新时间:2023-12-04 16:26:04 24 4
gpt4 key购买 nike

网格加载服务器绑定(bind)的 b/c。
所有其他操作要么发布到错误的路线,要么发布到默认操作:
将帖子插入/EditOrder 操作
将帖子编辑为
这个地址:
http://localhost:20588/Orders/EditOrder/sdsddd?OrderID=2&CustomerID=1&ItemsInOrderGrid-mode=edit
这是没有意义的(sdsddd 是 ItemID)
没有到达 Controller 中 AJAX 部分内的断点。
知道我在做什么错吗?

谢谢,
丹妮

这是查看代码:

 <%=
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);
})

%>

这是 Controller 中的代码:
[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));
}

最佳答案

我不确定您是否需要 [HttpPost]属性(我认为 [GridAction] 就足够了)在那些 Ajax 操作上,也许尝试删除这些,看看是否能解决问题。

如果这不起作用,请尝试返回 GridModel在你的行动中:

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

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

您还可以使用类似于以下的语法(因为我认为 GridModel 喜欢拥有 total ):
        [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
});
}

关于asp.net-mvc-2 - Telerik Grid for ASP.NET MVC2 Ajax 绑定(bind)不起作用/路由到错误的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4669890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com