gpt4 book ai didi

c# - 使用 MVC 模型显示只读文本

转载 作者:行者123 更新时间:2023-11-30 14:33:42 26 4
gpt4 key购买 nike

我有一个 MVC 模型,其属性定义为:

[DisplayName("Service Version")]
public string ServiceVersion { get; set; }

在屏幕上,我希望它显示为:

Service Version: 0.1

'ServiceVersion' 有版本号。

在 View 中,我有:

@model Main_UI.Models.HomeModel

然后:

@Html.LabelFor(m=>m.ServiceVersion) @Html.DisplayText(Model.ServiceVersion)

这是不正确的,因为我没有显示值部分。出现标签,但没有版本号。我做错了什么?

编辑:改变

@Html.DisplayText(Model.ServiceVersion)

,只是

@Model.ServiceVersion

已经解决了。这是执行此操作的正确方法吗?

最佳答案

您可以尝试@karthik 在评论中提到的内容,也可以使用该属性

[ReadOnly(true)]
[DisplayName("Service Version")]
public string ServiceVersion { get; set; }

并在 View 中使用默认值

@Html.LabelFor(m=>m.ServiceVersion) @Html.DisplayText(Model.ServiceVersion)

关于c# - 使用 MVC 模型显示只读文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15715842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com