显示与MVC模式只读文本 [英] Display readonly text with MVC Model
问题描述
我有一个MVC模型,定义为一个属性:
I have an MVC Model, with a property defined as:
[DisplayName("Service Version")]
public string ServiceVersion { get; set; }
在屏幕上,我希望它显示为:
On the screen, I want it to display as:
服务版本: 0.1
ServiceVersion'具有版本号
'ServiceVersion' has the version number.
在看,我有:
@model Main_UI.Models.HomeModel
和则:
@Html.LabelFor(m=>m.ServiceVersion) @Html.DisplayText(Model.ServiceVersion)
这是不正确的,因为我得到的值部分显示什么。标签出现,但没有版本号。我在做什么错了?
This isn't correct, as I get a nothing displayed for the value part. The label appears, but no version number. What am I doing wrong?
编辑:更改
@ Html.DisplayText(Model.ServiceVersion)
@Html.DisplayText(Model.ServiceVersion)
,只是
@ Model.ServiceVersion
@Model.ServiceVersion
已经固定它。这是做的正确方法?
has fixed it. Is this the right way to do this?
推荐答案
要么你可以试试哪些@karthik在评论中提到或者你可以使用属性
either you can try what @karthik has mentioned in the comments or you can use the attribute
[ReadOnly(true)]
[DisplayName("Service Version")]
public string ServiceVersion { get; set; }
和在视图中使用默认
@Html.LabelFor(m=>m.ServiceVersion) @Html.DisplayText(Model.ServiceVersion)
这篇关于显示与MVC模式只读文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!