我有一个包含 Telerik 网格的视图:
索引.cshtml
@(Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(c => c.CustomerID))
.ToolBar(toolBar => toolBar.Template(
@<text>
<button id="feedback-open-button" title="Add Customer" class="t-button t-state-default">Add</button>
</text>))
.Columns(columns =>
{
columns.AutoGenerate(column =>
{
//customize autogenereted column's settings
column.Width = "150px";
if (column.Member == "CustomerID")
column.Visible = false;
});
columns.Command(commands => commands
.Custom("editCustomer")
.Text("Edit")
.DataRouteValues(route => route.Add(o => o.CustomerID).RouteKey("CustomerID"))
.Ajax(true)
.Action("EditCustomer", "Grid"))
.HtmlAttributes(new { style = "text-align: center" })
.Width(150);
})
)
我想使用弹出窗口向此网格添加/编辑记录。我使用了 Telerik 窗口,在其中我打开了另一个视图作为部分视图来添加/编辑记录。这是窗口的代码以及我如何将其作为“添加功能”的弹出窗口打开。
索引.cshtml
@{ Html.Telerik().Window()
.Name("Window")
.Title("Add / Edit Customer")
.Content(@<text>
@Html.Partial("AddEditCustomer", new Customer());
</text>)
.Width(400)
.Draggable(true)
.Modal(true)
.Visible(false)
.Render();
}
@{ Html.Telerik().ScriptRegistrar()
.OnDocumentReady(@<text>
// open the initially hidden window when the button is clicked
$('#feedback-open-button')
.click(function(e) {
e.preventDefault();
$('#Window').data('tWindow').center().open();
});
</text>);
}
我尝试使用相同的窗口进行编辑。但是我在将客户对象传递给窗口中的部分视图时遇到问题。
客户控制器.cs
public JsonResult EditCustomer(int CustomerID)
{
var model = CustomerModel._CustomerCollection.FirstOrDefault(o => o.CustomerID == CustomerID);
return Json(new { customer = model });
}
索引.cshtml
<script type="text/javascript">
function onComplete(e) {
if (e.name == "editCustomer") {
var detailWindow = $("#Window").data("tWindow");
var customer = e.response.customer;
detailWindow.center().open();
}
}
</script>
如何将此“客户”对象传递给弹出窗口内的局部视图?