0

私は ASP.NET 4.5 (PHP に休憩を与える) を初めて使用し、ラベルのレンダリングに固執しています。

必要な Models を定義する ViewModel があります。

 public class TransactionsViewModel {
    public IEnumerable<Transaction> Transactions { get; set; }
    public IEnumerable<Area> Areas { get; set; }

    public IEnumerable<Mistake> Mistakes { get; set; }
    ...
 }

トランザクションは、単純なプロパティを持つ単なる別のモデルです。今度は、トランザクション プロパティの 1 つのラベルを表示したいと考えています。

私のビューには強力なタイプの TransactionsViewModel があります

@model AuditSystem.ViewModels.TransactionsViewModel

これは、オーバーライド時に HTMLHelper のタイプが < TransactionsViewModel> であることを意味します。

作成しようとしているメソッドプロトタイプは次のとおりです。

public static MvcHtmlString LabelFor<TModel, TClass, TValue>(
        this HtmlHelper<TModel> helper,
        IEnumerable<TClass> model,
        Expression<Func<TClass, TValue>> expression,
        object htmlAttributes
    )

< TModel> は TransactionsViewModel (厳密に型指定) であり、< TClass> は (Transaction) です。

Expression> の式が必要なため、helper.LabelFor を呼び出そうとすると問題が発生しますが、Func を渡す必要があります。

有効な型で式を再構築しようとしましたが、html.labelfor の呼び出しでスタックし、型キャストが機能しません。

4

1 に答える 1