【发布时间】:2011-11-10 07:27:35
【问题描述】:
如果我有一个带有部分文件的模型
[MetadataType(typeof(ClassAMetadata))]
public partial class ClassA: IStructualObject
{
}
public class ClassAMetadata
{
[DisplayName("Var B:")]
public object VarB { get; set; }
}
Var B 是一个日期时间!
然后我有一个使用 ClassA 的控制器的 ViewModel (ClassAViewwModel),在这个 ViewModel I ClassA 中,它还有一个 VarB 的 DateTimeViewModel,原因是在我的应用程序中 DateTime 显示为 3 个字段 Date、Hour 和分钟。
然后我为我的 DateTimeViewModel 创建了一个模板。见代码:
@model ViewModels.DateTimeViewModel
<div >
<span class="editor-label">
@Html.LabelFor(m => m)
</span>
<span class="editor-field">
@Html.TextBoxFor(m => m.Date, new { id = "participating_airborne_@ViewData_" + ViewData["cssname"] + "_resource_date", @class="datepicker dato", maxlength="10"})
</span>
<span class="editor-field">
@Html.TextBoxFor(m => m.Hour, new { id = "participating_airborne_" + ViewData["cssname"] + "_resource_hours", @class = "time", maxlength = "2" })
</span>:<span class="editor-field">
@Html.TextBoxFor(m => m.Minute, new { id = "participating_airborne_" + ViewData["cssname"] + "_resource_minutes", @class = "time", maxlength = "2" })
</span>
<span>
@Html.ValidationMessageFor(m => m.Date)
@Html.ValidationMessageFor(m => m.Hour)
@Html.ValidationMessageFor(m => m.Minute)
</span>
</div>
然后我想要以某种方式从我的 VarB 中获取 DisplayName,以便在我在 DateTimeViewModel(或类似的东西)上执行 @Html.LabelFor(m => m) 时显示,所以我需要一种方法来读取部分信息,这可能吗?
【问题讨论】:
标签: c# asp.net .net asp.net-mvc-3