asp.net-mvc 如何显示模型的字符串属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20554707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display a string property of Model
提问by Greg Gum
I am sure this is very simple, but I haven't found it yet.
我相信这很简单,但我还没有找到。
I have an Model with a property of Message that I will set in the control.
我有一个属性为 Message 的模型,我将在控件中设置该属性。
What is the Html helper for this?
什么是 Html 助手?
For example,
例如,
Html.TextBoxFor(m=> m.Message)
shows me the message, but it's in a textbox. I don't want the textbox, just the value.
向我展示了消息,但它在一个文本框中。我不想要文本框,只想要值。
Greg
格雷格
回答by Konrad Kokosa
You can use two syntax:
您可以使用两种语法:
@Html.DisplayFor(m => m.Message)
or
或者
@Model.Title
You can read this questionfor details.
您可以阅读此问题以了解详细信息。

