0
?((webEPOS.Models.cPrice)((new System.Collections.Generic.Mscorlib_CollectionDebugView<webEPOS.Models.cProductOption>(this.ProductOptions)).Items[0])).MainPrice
12

これをアンラップして、メイン価格の mvc ビューで実際の値を取得するにはどうすればよいですか?

this.ProductOptions[0]
{MAFIA webEPOS.Models.cProductSize}
    base {webEPOS.Models.cPrice}: {MAFIA webEPOS.Models.cProductSize}
    IsDeleted: false
    OptionID: 12
    ParentName: "MAFIA"
    Position: 0
    ProductID: 7
    SizeDescription: "7''"
    SizeID: 1
    SizeInfo: {webEPOS.Models.cProductSize}
4

1 に答える 1

1

あなたの質問には詳細が必要なので、ここで多くの仮定を立てていますが、cPrice は MainPrice のプロパティを持つ基本クラスのように見えますか?

したがって、View 宣言が

@model List<cProductOption>

そして、次のように ActionResult から製品オプションを渡しました。

return View(this.ProductOptions);

上記のコードの記述方法により、Items コレクションの型が緩くなっていると思います。ビューでその種のコードをいじくり回したくはありません。それを適切に取得する cProductOption の拡張メソッドを作成することにより、サーバー側で安全に実行します。

public static decimal MainPrice (this cProductOption cproductOption) {

    decimal returnValue = 0m;

    try {
        // returnValue = try and get it from .Items[0], casting to the type you need and/or seeing if the necessary relationships exist.
    }
    catch(Exception exception){
        // log the possible exception
    }

    return returnValue;
}

次に、継承を自分のやり方で整理したので、Model リストを単純に繰り返すことができます。

@foreach (cProductOption cproductOption in Model) {
    @cProductOption.MainPrice()
}

私が言ったように、私はこれのいくつかについて知識に基づいた推測を行っていますが、うまくいけば、それがあなたにいくつかの指針を与えるでしょう. あなたのアプリで頑張ってください!

于 2013-04-20T16:53:46.287 に答える