English 中文(简体)
选修模型部分显示器
原标题:Parsing model partial DisplayName to view model template

如果我有一个包含部分档案的模型

[MetadataType(typeof(ClassAMetadata))]
public partial class ClassA: IStructualObject
{
}

public class ClassAMetadata
{
    [DisplayName("Var B:")]
    public object VarB { get; set; }
}

And Var B is a DateTime!

然后,我对使用A级的管制人员持有“观点”(ClassAViewwdel)”,在这种观点中,我还有VarB的“时间意见”,其理由是,在我的申请时间上,时间段为3个领域。

然后,我为我时代的摩德尔创造了一个模板。 见《刑法》:

    @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>

我当时想要的是,从我的瓦伦布获得显示Name的显示器,以在我做“Html”时显示。 LabelFor(m =>m) on mytimeViewModel 因此,我需要一种方式来解读部分信息,这是可能的吗?

最佳回答

你们应当能够从模型元数据中找到目前模型的标语:

ViewData.ModelMetadata.GetDisplayName()

http://www.un.org。

如果您有这样的模式:

public class ClassA
{
    [DisplayName("Var B:")]
    public DateTimeViewModel VarB { get; set; }
}

而后是班级 您认为,这种财产是:

@Html.EditorFor(x => x.VarB)

然后,它应当使用您的“日记号”模板,并从模型元数据中提取显示名称。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签