如何写IF条件的网络格列如何写、格列、条件、网络

2023-09-06 16:12:49 作者:不好意思,暴发户@

我有得到错误的创造,如果条件到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的它,而不是使用网址帮手,你不应该做的。

EXCEL里,若想让一列数据大于另一列数据时自动显示红色,如何设置 是用IF函数,还是条件格式,还是其它

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.