如何写IF条件的网络格列 [英] How to write IF condition in column of Web grid

查看:158
本文介绍了如何写IF条件的网络格列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有得到错误的创造,如果条件到WEB格列等等......请帮助提高我的code和解决了我的概率....

  grid.Column(状态,格式为:项目=>
@<文本>
@if(item.Is_active =真)
{
    @&所述; A HREF =Url.Action(UserStatus,管理员)>&所述; IMG SRC =../../图像/ Active.png/>&所述; / a取代;
} 其他
{
    @&所述; A HREF =Url.Action(UserStatus,管理员)>&所述; IMG SRC =../../图像/ Deactive.png/>&所述; / a取代;
}
< /文>)
 

解决方案

以下应该工作:

  grid.Column(
    状态,
    格式:
        @< A HREF =@ Url.Action(UserStatus,管理员)>
            < IMG SRC =@ Url.Content(的String.Format(〜/图片/ {0} png格式,item.Is_active?主动:去激活)),ALT =/>
        &所述; / a取代;
)
 

请注意我有固定的的src 你的形象,因为你已经很难codeD的它,而不是使用网址帮手,你不应该做的。

i have get error the create the if condition in to column of WEB GRID so...please help to improve my code and solved to my prob....

grid.Column("Status", format: item => 
@<text>
@if (item.Is_active = true)
{ 
    @<a href="Url.Action("UserStatus", "Admin")"><img src="../../images/Active.png"/></a> 
} else
{ 
    @<a href="Url.Action("UserStatus", "Admin")"><img src="../../images/Deactive.png"/></a> 
}
</text>),

解决方案

The following should work:

grid.Column(
    "Status", 
    format: 
        @<a href="@Url.Action("UserStatus", "Admin")">
            <img src="@Url.Content(string.Format("~/images/{0}.png", item.Is_active ? "Active" : "Deactive"))" alt="" />
        </a>
)

Notice how I have fixed the src of your image because you have hardcoded it instead of using an url helper which you should never do.

这篇关于如何写IF条件的网络格列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆