Change Telerik grid columns based on Appsetting
I have a Html.Telerik().Grid() that is bound to a model in my MVC view. I want it to return a link based on a value in the appsettings in the web.c开发者_Go百科onfig. Basically, if this is the dev server then show the links but not on the production server, is that possible? I use Ajax binding and my bound column looks as follows:
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);
I want the status.txt to be a link on development but not on production (this is how it is now)
Thank you. Jack
You need to set the client template in a different way depending on the fact your application is deployed or not:
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);
}
I actually achieved this by adding a property in the domain object as follows:
public bool isProduction
{
get
{
return ConfigurationManager.AppSettings["ActivationURL"].Contains("production");
}
}
and then in the view I had:
.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);
This way I cater for the initial server bound data and the later Ajax bound data.
精彩评论