如何在我的mvc视图中从中提取主要价格值?

时间:2022-02-09 20:58:05
?((webEPOS.Models.cPrice)((new System.Collections.Generic.Mscorlib_CollectionDebugView<webEPOS.Models.cProductOption>(this.ProductOptions)).Items[0])).MainPrice
12

How can i unwrap this to get actual value at my mvc view for main price?

我怎样才能解开这个以获得我的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}

1 个解决方案

#1


1  

I'm making lots of assumptions here as your question needs more detail, but it looks like cPrice is your base class with a property of MainPrice?

我在这里做了很多假设,因为你的问题需要更多的细节,但看起来cPrice是你的基类,具有MainPrice的属性?

So if your View declaration is

因此,如果您的View声明是

@model List<cProductOption>

And you've passed the product options from your ActionResult like so:

你已经从你的ActionResult传递了产品选项,如下所示:

return View(this.ProductOptions);

I'm guessing that the Items collection is loosely typed because of the way you've written that code above. You don't want to be phlucking about with that kind of code in the view; do it safely server side by writing an extension method on cProductOption that will grab it gracefully:

我猜测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;
}

Then because you have your inheritance sorted out the way you do you can simply iterate through the Model list:

然后,因为您的继承按照您的方式进行了整理,您可以简单地遍历模型列表:

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

Like I said, I'm making educated guess at some of this, but hopefully it gives you some pointers. Good luck with your app!

就像我说的那样,我正在对其中一些做出有根据的猜测,但希望它能为你提供一些指导。祝你的应用好运!

#1


1  

I'm making lots of assumptions here as your question needs more detail, but it looks like cPrice is your base class with a property of MainPrice?

我在这里做了很多假设,因为你的问题需要更多的细节,但看起来cPrice是你的基类,具有MainPrice的属性?

So if your View declaration is

因此,如果您的View声明是

@model List<cProductOption>

And you've passed the product options from your ActionResult like so:

你已经从你的ActionResult传递了产品选项,如下所示:

return View(this.ProductOptions);

I'm guessing that the Items collection is loosely typed because of the way you've written that code above. You don't want to be phlucking about with that kind of code in the view; do it safely server side by writing an extension method on cProductOption that will grab it gracefully:

我猜测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;
}

Then because you have your inheritance sorted out the way you do you can simply iterate through the Model list:

然后,因为您的继承按照您的方式进行了整理,您可以简单地遍历模型列表:

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

Like I said, I'm making educated guess at some of this, but hopefully it gives you some pointers. Good luck with your app!

就像我说的那样,我正在对其中一些做出有根据的猜测,但希望它能为你提供一些指导。祝你的应用好运!