I have model class like so:
Inside a Kendo Grid, I'd like to display a link to the Customer, but as the Customer can be null, I'm having trouble getting this link to only show when the customer is not null. Below is the client template I'm trying to use:
This just gives me a template error, though.
public
class
ServerModel
{
public
Guid Id {
get
;
set
; }
public
CustomerModel Customer {
get
;
set
; }
public
string
Name {
get
;
set
; }
}
Inside a Kendo Grid, I'd like to display a link to the Customer, but as the Customer can be null, I'm having trouble getting this link to only show when the customer is not null. Below is the client template I'm trying to use:
@(Html.Kendo().Grid(Model)
.Name(
"Grid"
)
.Columns(columns =>
{
columns.Bound(s => s.Name)
.ClientTemplate(
"<a href='"
+ Url.Action(
"Details"
,
"Server"
) +
"/#= ID #'>#= Name #</a>"
);
columns.Bound(s => s.Hostname);
columns.Bound(s => s.Customer.Name).Title(
"Customer"
)
.ClientTemplate(
"#= Customer ? '<a href=\'"
+ Url.Action(
"Details"
,
"Customer"
) +
"/#= ID #\'>#= Customer.Name #</a>' : 'Unknown'#"
);
columns.Bound(s => s.Reported).Title(
"Last Reported (UTC)"
).Format(
"{0:yyyy-MM-dd hh:mm:ss tt}"
);
})
This just gives me a template error, though.