开发者

Showing a default value in a WebGrid when a null is present?

I've got Webgrid sourced to a EF4 entity with navigation properties (basically relationships)

If the webgrid encounters a 开发者_Go百科null for that foreign key it errors out because it's looking for that object, which in this case doesn't exist.

Is it possible to catch when a column item is null and default to a value within the Webgrid helper?


I guess the follwoing code should serve your purpose if I am correctly relating to your problem. Below Trigger is the navigated entity which we will get by include in linq and we can put a check like below when this entity is null.

grid.Column("Job", format: @<text>  @if (@item.Trigger !=null) { <span> Write your default code here .</span> } </text> close text tag here ),

Hope that solves your problem.

I noticed after posting 'text' is getting truncated in this forum so put text in < and > between 2 @ as you can see and also close that text tag before the final ).

All the best.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜