显示是/否,而不是复选框在ASP.Net MVC的视图 [英] Showing Yes/No instead of checkbox in the View of ASP.Net MVC

查看:238
本文介绍了显示是/否,而不是复选框在ASP.Net MVC的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的ASP.Net / MVC。我创建了一个观点,我从一个模型填充。
我创建了模型中的每个项目行,以显示模型项目的它们的属性/属性。

I am very new to ASP.Net / MVC . I have created a View that I am populating from a model. I am creating a rows for each item in the model to show their properties/attributes of model item.

一位成员是一个布尔值,名称上演。在查看我想,如果真或否,如果假以显示为是。用户将只能读它,就这么简单的文本是/否应足够了。

One of the member is a bool , name is Staged. In the View I want to display it as Yes if true or No if false. The user will only be able to read it, so simple text Yes/No shall be sufficient.

我用下面的code在CSHTML

I am using the following code in the cshtml

    <td>
        @Html.DisplayFor(modelItem => item.Staged)         
   </td>

然而,这显示了地方一个复选框,我怎么能显示它是/否?

This however shows a checkbox in the place, how can I show it as Yes/No ?

谢谢,

推荐答案

您可以使用自定义的HTML帮助扩展方法是这样的:

You could use a custom html helper extension method like this:

@Html.YesNo(item.Staged)

下面是code此:

public static MvcHtmlString YesNo(this HtmlHelper htmlHelper, bool yesNo)
{
    var text = yesNo ? "Yes" : "No";
    return new MvcHtmlString(text);
}

此方式,您可以用剃刀code一行再次使用它整个网站。

This way you could re-use it throughout the site with a single line of Razor code.

这篇关于显示是/否,而不是复选框在ASP.Net MVC的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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