【问题标题】:Client template not working with custom helper action methods客户端模板不适用于自定义辅助操作方法
【发布时间】:2011-09-02 16:57:08
【问题描述】:

我正在使用 MVC Telerik 控件和带有剃刀视图引擎的 ASP.NET MVC 3。我有自己的路由辅助方法,例如:

public static object CategoryEdit(this UrlHelper urlHelper, int categoryId)
{
   return new { controller = "Category", action = "Edit", id = categoryId };
}

我有一个 AJAX 网格,我有我自己的列模板,其中有一个链接到类别控制器中的编辑操作方法,但我不知道如何正确显示它。目前我有这个,但它不工作:

column.Bound(x => x.Id)
   .ClientTemplate("<a href=\"" + Url.RouteUrl(Url.CategoryEdit(Int32.Parse("<#= Id #>"))) + "\">Edit</a>")
   .Title("Action")
   .Width(50);

当网格加载时会出现以下异常:

输入字符串的格式不正确。

所以我假设Int32.Parse("&lt;#= Id #&gt;") 不正确。

【问题讨论】:

  • 你能解释一下什么是不工作的
  • 是的,“”不是有效数字。 ClientTemplate 中指定的代码只是一个字符串,稍后将被解释为模板。它不会在客户端运行您的服务器端代码。
  • @Atanas:那你有解决办法吗?
  • 解决方案已经给出,但其作者似乎已删除他的回复。答案是将 嵌入到操作链接的路由值中。

标签: c# asp.net-mvc-3 telerik telerik-grid telerik-mvc


【解决方案1】:

试试这个:

public static object CategoryEdit(this UrlHelper urlHelper, string categoryId)
{
   return new { controller = "Category", action = "Edit", id = categoryId };
}

column.Bound(x => x.Id)
   .ClientTemplate("<a href=\"" + Url.RouteUrl(Url.CategoryEdit("<#= Id #>")) + "\">Edit</a>")
   .Title("Action")
   .Width(50);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 2014-10-27
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多