2015-08-18 33 views
0

我想結合我的razor看法,但得到的錯誤控制:如何綁定模型控制在MVC 4

這裏是我的Order型號:

public class OrderViewModel 
    { 
     public int Id { get; set; } 


     public AreaCatalog Area { get; set; } 

     [Display(Name="Sub Total")] 
     public int SubTotal { get; set; } 

     public int Discount { get; set; } 

     [Display(Name = "Delivery Fee")] 
     public int DeliveryFee { get; set; } 

     [Display(Name = "Total Amount")] 
     public int TotalAmount { get; set; } 

     public List<ProductViewModel> Product { get; set; } 

    } 

包含在ProductOrderViewModel如下:

public class ProductOrderViewModel 
    { 
     public List<ProductViewModel> Products { get; set; } 

     public List<OrderViewModel> Orders { get; set; } 
    } 

這裏是我的控制器代碼:

 public ActionResult Edit() 
     { 
      ResponseModel result = new ResponseModel(); 
      result = new Logic().GetProducts(); 
      //var model = new ProductOrderViewModel() { Products = result.Model, Orders = yy }; 
      var model = new ProductOrderViewModel() { Products = result.Model }; 
      if (result.Success) 
       return View(model); 

      return View(); 

     } 

這裏是我的視圖代碼:

@model ProductOrderViewModel 
@using Helpers 
@using ViewModels; 
@{ 
    ViewBag.Title = "Edit"; 
} 

@Html.EnumDropDownListFor(m => m.Orders.Area, new { @name = "area", @style = "width:295px; height:25px;margin-left:5px;" }) 

和錯誤是:

不包含關於「區域」和沒有擴展方法「區域」接受類型的第一個參數定義「系統.Collections.Generic.List

請指導我這個問題

+0

什麼行是錯誤? – Oluwafemi

+0

@Oluwafemi包含EnumDropDownListFor的行。 – ARC

+0

你可以在課堂上看到什麼? – Oluwafemi

回答

3

的錯誤說:does not contain a definition for 'Area' and no extension method 'Area' accepting a first argument of type 'System.Collections.Generic.List

Area是您的OrderViewModel的財產,但不是List<OrderViewModel>

和你實際上是試圖做一些事情,如:

//Assume: 
List<OrderViewModel> myList = new List<OrderViewModel>(); 

和你想得出EnumDropDownlistFormyList.Area。這是不可能的。因爲Area不是Generic List的屬性

+0

但以這種方式得到錯誤\t不能隱式地將類型'Cygnus.Global.ViewModels.OrderViewModel'轉換爲'System.Collections.Generic.List '\t D:\ CygnusDev \ GDR \ OST \ OST \ Cygnus.Website.Base \ Controllers \ OrderController.cs – ARC

+0

Downvoter,歡迎您在這裏發表評論。請指出問題所在? – Zeeshan