سؤال

لدي فئة تحتوي على القاموس قيمة العقار (حقيبة خاصية) بجانب الخصائص العادية. أرغب في عرض مجموعة من هذا الكائن في جدول باستخدام الشبكة من MVCContrib.

الفصل:

public class ObjectWithPropertyBag
{
   public string Property1 { get; set; }
   public string Property2 { get; set; }   

   public Dictionary<string, string> PropertyBag { get; set; }
}

بلدي GridModel (ObjectWithPropertybaggridelodel):

Column.For(x => x.Property1);
Column.For(x => x.Property2);
Column.For(x => x.PropertyBag)//how to display keys as columns and values as table data

وجهة نظري:

Html.Grid(ViewData.Model.ObjectWithPropertyBag).WithModel(new ObjectWithPropertyBagGridModel())

هل هناك أي طريقة للتكرار من خلال القاموس وإنشاء الأعمدة؟

شكرا.

هل كانت مفيدة؟

المحلول

شيء مثل:

foreach (var prop in PropertyBag) column.For(prop.Value).Named(prop.Key);

لا أتذكر بناء الجملة الدقيق، ولكن بقدر ما أتذكر أنك لا تضطر إلى استخدام Lambdas. أو ربما يجب أن يكون. (""). القيمة (Prop.Value) ... فقط تحقق من مصادر الشبكة (أو Google) للحصول على الحمل الزائد.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top