使用 mvc3 有条件地在 Telerik 网格中显示链接
我正在尝试向网格添加操作链接。但前提是存在条件(用户被锁定)。我无法让它在 mvc3 (razor) 中工作。什么也没有显示。
我已经尝试过了:
@Html.Telerik().Grid(Model.Users).Name("UserGrid").DataKeys(dataKeys => dataKeys.Add(o => o.UserName)).Columns(columns =>
{
columns.Template(s => Html.ActionLink(s.UserName, "Details", new { id = s.ProviderUserKey })).Title("Username (<i>click to edit</i>)");
columns.Template(s => { if (s.IsLockedOut) Html.ActionLink("Unlock", "UnlockUser", new { username = s.UserName }, new { @class = "unlockimage" }); });
}).Pageable().Sortable().Filterable()
即使我删除了 if(cond)... 我也无法显示操作链接。但是如果我不使用 lambda 呢?它确实有效,但始终明显显示。
columns.Template(s => Html.ActionLink("Unlock", "UnlockUser", new { username = s.UserName }, new { @class = "unlockimage" }) );
非常感谢任何帮助。
I'm trying to add an action link to a grid. But only if a condition exists (the user is locked out). I can't get this to work in mvc3 (razor). Nothing is displayed.
I've tried:
@Html.Telerik().Grid(Model.Users).Name("UserGrid").DataKeys(dataKeys => dataKeys.Add(o => o.UserName)).Columns(columns =>
{
columns.Template(s => Html.ActionLink(s.UserName, "Details", new { id = s.ProviderUserKey })).Title("Username (<i>click to edit</i>)");
columns.Template(s => { if (s.IsLockedOut) Html.ActionLink("Unlock", "UnlockUser", new { username = s.UserName }, new { @class = "unlockimage" }); });
}).Pageable().Sortable().Filterable()
and even when I remove the if(cond)... I can't get the actionlink to display. However if I don't use the lambda? it does work but is obviously displayed all the time.
columns.Template(s => Html.ActionLink("Unlock", "UnlockUser", new { username = s.UserName }, new { @class = "unlockimage" }) );
any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看此在线演示如何演示如何在 Razor 中使用模板列。以下是摘录:
Check this online demo how which shows how to use template columns in Razor. Here is an excerpt:
上面 Rich 的解决方案帮助我制定了满足需求的解决方案。我有一个列可以显示简单的文本、电子邮件地址或网址。我想让电子邮件地址和网址成为可选择的热链接。下面是我的解决方案的一个发挥。
The solution from Rich above helped me craft a solution for needs. I have a single column that can display simple text, email address, or a url. I wanted to make the email address and url a selectable hot link. Below is an exert of my solution.