Telerik MVC 在模板列中指定您自己的操作路由器
我正在使用最新版本的 Telerik MVC
以及 ASP.NET MVC 3
和 Razor
视图引擎。
我有以下列声明:
column.Bound(x => x.Id)
.Template(x => Html.ActionLink("Edit", "Edit", new { id = x.Id }))
.Title("Action")
.Width(100);
我创建了自己的方法,该方法路由到我想使用的此编辑操作方法,但不确定如何使用?
public static object AdministrationCategoryEdit(this UrlHelper urlHelper, int categoryId)
{
Check.Argument.IsNotNull(urlHelper, "urlHelper");
return new { area = "Administration", controller = "Category", action = "Edit", id = categoryId };
}
如何在列声明中引用上述方法并通过类别 ID 传递它?
例如,如果我想将它与按钮一起使用,那么我会执行以下操作:
$('#btnEdit').click(function () {
window.location = '@Url.RouteUrl(Url.AdministrationCategoryEdit(Model.Id))';
});
I am using the latest version of Telerik MVC
with ASP.NET MVC 3
and the Razor
view engine.
I have the following column declaration:
column.Bound(x => x.Id)
.Template(x => Html.ActionLink("Edit", "Edit", new { id = x.Id }))
.Title("Action")
.Width(100);
I have created my own method that routes to this Edit action method which I would like to use but not sure how to?
public static object AdministrationCategoryEdit(this UrlHelper urlHelper, int categoryId)
{
Check.Argument.IsNotNull(urlHelper, "urlHelper");
return new { area = "Administration", controller = "Category", action = "Edit", id = categoryId };
}
How would I reference the above method in my column declaration and pass it through the category ID?
For example, if I want to use it with a button, then I would do something like:
$('#btnEdit').click(function () {
window.location = '@Url.RouteUrl(Url.AdministrationCategoryEdit(Model.Id))';
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于所有
ActionLink
方法都有一个单独的操作参数,因此没有完全符合您的要求的方法。但是,即使现在指定了两次操作,它也应该适用于以下代码。另一种方法是创建一个类似于
ActionLink
的 HTML 帮助程序,它现在仅生成路由参数,但生成链接的完整代码。There is no perfect match for your requirement since all
ActionLink
methods have a separate parameter for the action. However, it should work with the following code even though the action is now specified twice.An alternative would be to create an HTML helper similar to
ActionLink
that now only generates the route parameters but the complete code for a link.