您好我正在使用asp.net mvc3中的ajax将部分视图返回到div。此视图包含teleric grid
这是我的观看代码
<input type="text" style="width: 320px;border: 1px solid rgb(177, 177, 177);" id="OrderIdToImport" onkeydown = "return (event.keyCode!=13);" />
<input type="button" class="t-button" value="Import" name="Add" id="ImportProducts" onclick="ImportProductsFromOrder();" />
<div id="ImportedProducts">
</div>
<script type="text/javascript">
function ImportProductsFromOrder() {
var OrderID = $('#OrderIdToImport').attr('value');
if(OrderID=="")
{
alert('Please Specify OrderID');
}
$.ajax({
cache:true,
type: "POST",
url: "@(Url.Action("ImportProducts", "Order"))",
data: "orderId=" + OrderID ,
success: function (data) {
$("#ImportedProducts").html(data);
return false;
},
error:function (xhr, ajaxOptions, thrownError){
//alert('Failed to subscribe.');
},
complete: function() { }
}); // end ajax code
return false;
}
</script>
以下是我的控制器操作
public ActionResult ImportProducts(int orderId)
{
var model = new ImportedProductsModel();
model.Id = orderId;
var order = _orderService.GetOrderById(model.Id);
return PartialView("ImportProducts", model);
}
[GridAction(EnableCustomBinding = true)]
public ActionResult ImportedProductsInGrid(GridCommand command, ImportedProductsModel model)
{
var order = _orderService.GetOrderById(model.Id);
var orderProductvariants = order.OrderProductVariants.Where(o => !o.Deleted);
var gridModel = new GridModel<ImportedProductsModel>
{
Data = orderProductvariants.Select(x =>
{
return new ImportedProductsModel()
{
Id = x.Id,
Name = x.ProductVariant.Product.Name,
Quantity = x.Quantity,
UnitPriceExclTax = x.UnitPriceExclTax,
TaxRate = x.UnitPriceExclTax / (x.UnitPriceExclTax - x.UnitPriceExclTax),
UnitPriceInclTax = x.UnitPriceInclTax,
MRP = x.OldPrice,
UnitCost = x.UnitCost
};
}),
Total = orderProductvariants.Count()
};
return new JsonResult
{
Data = gridModel
};
// return PartialView("SearchProduct", model.ProductSearchResult);
}
我的部分观点如下
@model ImportedProductsModel
@using Telerik.Web.Mvc.UI
@using (Html.BeginForm())
{
<p>
</p>
<table class="adminContent">
<tr>
<td>
@(Html.Telerik().Grid<ImportedProductsModel>()
.Name("importedproducts-grid")
.ClientEvents(events => events.OnDataBinding("onDataBinding"))
.Columns(columns =>
{
columns.Bound(x => x.Id);
columns.Bound(x => x.Name);
columns.Bound(x => x.Quantity);
columns.Bound(x => x.UnitPriceExclTax);
columns.Bound(x => x.TaxRate);
columns.Bound(x => x.UnitPriceInclTax);
columns.Bound(x => x.MRP);
columns.Bound(x => x.UnitCost);
})
.Pageable(settings => settings.PageSize(40).Position(GridPagerPosition.Both))
.DataBinding(dataBinding => dataBinding.Ajax().Select("ImportedProductsInGrid", "Order", Model))
.EnableCustomBinding(true))
</td>
</tr>
</table>
<script type="text/javascript">
function onDataBinding(e) {
//alert('Hi');
}
</script>
}
我正在撤回请求的网址返回500错误
任何解决方案?
答案 0 :(得分:0)
尝试... ...
.DataBinding(dataBinding => dataBinding.Ajax().Select("ImportProducts", "Order", Model))
...
[GridAction(EnableCustomBinding = true)]
public ActionResult ImportProducts(GridCommand command, ImportedProductsModel model)
{
....
return View(new GridModel(gridModel));
}