2013-04-20 85 views
0
?((webEPOS.Models.cPrice)((new System.Collections.Generic.Mscorlib_CollectionDebugView<webEPOS.Models.cProductOption>(this.ProductOptions)).Items[0])).MainPrice 
12 

如何解开此问题以获得我的mvc视图的实际价值以获取主要价格?如何从我的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

我正在这里很多的假设你的问题需要更多的细节,但它看起来像cPrice是你的基类MainPrice的属性?

因此,如果您查看声明

@model List<cProductOption> 

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

return View(this.ProductOptions); 

我猜测,该项目集合是弱类型,因为你写过上面的代码的方式。你不想在视图中对这种代码感到困惑,通过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; 
} 

然后因为你有你的继承整理出来你做,你可以简单地通过模型列表迭代方式:

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

就像我说的,我正在对此进行有根据的猜测,但希望它能给你一些指示。祝你的程序好运!