0

我有一个 Html.Telerik().Grid() 绑定到我的 MVC 视图中的模型。我希望它根据 web.config 中的 appsettings 中的值返回一个链接。基本上,如果这是开发服务器,则显示链接但不在生产服务器上,这可能吗?我使用 Ajax 绑定,我的绑定列如下所示:

columns.Bound(f => f.TechnicalKey)
       .ClientTemplate("<# if (FileName != 'status.txt' && StatusText=='PROCESSED') { #><a href='/AType/DownloadAFile/<#= TechnicalKey #>'>Download</a> <# } else { #>Not available<# } #>")
       .Title("").Filterable(false);

我希望 status.txt 成为开发链接,而不是生产链接(现在就是这样)

谢谢你。杰克

4

2 回答 2

0

您需要根据应用程序的部署情况以不同的方式设置客户端模板:

if (/* some check to see if on production which is specific to your implementation */) {
columns.Bound(f => f.TechnicalKey)
       .ClientTemplate("<# if (FileName != 'status.txt' && StatusText=='PROCESSED') { #>Download <# } else { #>Not available<# } #>")
       .Title("").Filterable(false);

} else {
columns.Bound(f => f.TechnicalKey)
       .ClientTemplate("<# if (FileName != 'status.txt' && StatusText=='PROCESSED') { #><a href='/AType/DownloadAFile/<#= TechnicalKey #>'>Download</a> <# } else { #>Not available<# } #>")
       .Title("").Filterable(false);
}
于 2011-05-06T07:57:37.587 回答
0

我实际上是通过在域对象中添加一个属性来实现的,如下所示:

    public bool isProduction
    {
      get
      {
        return ConfigurationManager.AppSettings["ActivationURL"].Contains("production");
      }
    }

然后在我看来:

    .Columns(columns =>
                  {
                    columns.Bound(f => f.TechnicalKey)
                      .Template(f => { %>
                                          <% if (f.StatusText == "PROCESSED")
                                              {
                                                if (!f.isProduction || f.FileName != "status.txt")
                                                {                          
                                                  %><a href="/AType/DownloadAFile/<%= f.TechnicalKey %>">Download</a><%
                                                }
                                                else
                                                {
                                                  %>Not available<%
                                                }                                
                                              }
                                              else
                                              {
                                                %>Not available<%
                                              } 
                                            %>
                                    <% })
                      .ClientTemplate("<# if (StatusText=='PROCESSED') { if(!isProduction || FileName!='status.txt') { #><a href='/AType/DownloadAFile/<#= TechnicalKey #>'>Download</a> <# } else { #>Not available<# }} else { #>Not available<# } #>").Encoded(false).Title("").Filterable(false);

这样我就可以满足最初的服务器绑定数据和后来的 Ajax 绑定数据。

于 2011-05-08T18:52:43.750 回答