Asp.net mvc 如何获得<;#=Id#>;当传递给助手方法时

Asp.net mvc 如何获得<;#=Id#>;当传递给助手方法时,asp.net-mvc,asp.net-mvc-3,telerik,telerik-grid,telerik-mvc,Asp.net Mvc,Asp.net Mvc 3,Telerik,Telerik Grid,Telerik Mvc,我正在用ASP.netmvc3和razor一起使用。我还使用了最新版本的Telerik MVC 我的视图中有一个网格,显示应用程序列表。每个应用程序都有一个状态。我需要编写一个助手方法,根据每个应用程序的当前状态,在网格的每一行中显示链接。如果状态为1,则需要显示编辑链接。我拥有的助手如下所示: public static string ActionLinks(this HtmlHelper helper, string grantApplicationId, string grantAppli

我正在用
ASP.netmvc3
razor
一起使用。我还使用了最新版本的Telerik MVC

我的视图中有一个网格,显示应用程序列表。每个应用程序都有一个状态。我需要编写一个助手方法,根据每个应用程序的当前状态,在网格的每一行中显示链接。如果状态为1,则需要显示编辑链接。我拥有的助手如下所示:

public static string ActionLinks(this HtmlHelper helper, string grantApplicationId, string grantApplicationStateId)
{
     List<TagBuilder> linkList = new List<TagBuilder>();
     string actionLinks = string.Empty;

     if (grantApplicationStateId == "1")
     {
          // Edit link
          TagBuilder editLink = new TagBuilder("a");
          editLink.MergeAttribute("href", "/GrantApplication/Edit/" + grantApplicationId);
          editLink.InnerHtml = "Edit";
          linkList.Add(editLink);
     }

     foreach (TagBuilder link in linkList)
     {
          actionLinks += link.ToString() + "<br>";
     }

     return actionLinks;
}
column.Bound(x => x.Id)
     .ClientTemplate(@Html.ActionLinks("<#= Id #>", "<#= GrantApplicationStateType.Id #>"))
     .Title("Actions");
GrantApplicationStateType如下所示:

public class GrantApplicationListViewModel
{
     // Just partial properties
     public GrantApplicationStateType GrantApplicationStateType { get; set; }
}
public class GrantApplicationStateType : IEntity
{
     public int Id { get; set; }
     public string Name { get; set; }
}
调用上述helper方法时,grantApplicationStateId的值为“”。如何获取传递的值?我的意思是,如果传递的值是1,我如何得到1,因为当前它是“”

更新2012-02-06

我尝试了Darin的链接,在代码中使用了完全相同的示例,但更改了以下内容:

column.ActionLink("Open", "Edit", "GrantApplication", item => new { id = item.Id, applicationStateId = item.GrantApplicationStateType.Id });
我需要传递2个值。我需要对grant应用程序状态id执行几个if语句,然后将特定的操作链接返回到客户端。但在循环通过以下值时失败:

if (memberExpression.Expression is ParameterExpression)
     value = string.Format("<#= {0} #>", memberExpression.Member.Name);
else
     value = GetValue(memberExpression);
二者之间的区别是什么

然后在GetValue方法中失败,并显示以下消息:

variable 'item' of type MyProject.ViewModels.GrantApplicationListViewModel' referenced from scope '', but it is not defined

我无法使其正常工作,并且我查找了更多的样本,但没有找到任何样本。

您不能使用帮助器来完成此操作。在ASP.NET中,MVC帮助程序在服务器上运行。注意Telerik网格中的
ClientTemplate
名称?这意味着要在客户端上运行

它只是简单地使用
作为服务器端帮助程序的占位符,服务器端帮助程序将生成一些HTML和,Telerik网格将执行简单的字符串替换,以便输入仅在客户端已知的值

在您的服务器端
ActionLinks
helper被调用时,Telerik网格无法向您传递只有客户端才知道的实际值


您可以查看一下,以获得一个很好的扩展。

您的模型看起来如何它似乎可以工作,我只需修改它以适应我的场景。
value = GetValue(memberExpression);
variable 'item' of type MyProject.ViewModels.GrantApplicationListViewModel' referenced from scope '', but it is not defined