0

I want to bind controls on my razor view but getting error:

here is my Order model:

    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; }

    }

that is included in ProductOrderViewModel as below:

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

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

here is my controller code:

        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();

        }

and here is my view code:

@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;" })

and Error is :

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

Please guide me through this problem

12
  • on what line is the error? Commented Aug 18, 2015 at 12:45
  • @Oluwafemi the line containing EnumDropDownListFor . Commented Aug 18, 2015 at 12:46
  • What is in Orders can you show the class? Commented Aug 18, 2015 at 12:47
  • It appears that Areas might be some sort of List that has not been initialized in your model class (via constructor), as it appears you are not setting that value in your Edit action. Please add sample code of your ProductOrderViewModel. Commented Aug 18, 2015 at 12:49
  • @Oluwafemi I have edited my question please see it and guide me where to change Commented Aug 18, 2015 at 12:50

1 Answer 1

3

as error says: does not contain a definition for 'Area' and no extension method 'Area' accepting a first argument of type 'System.Collections.Generic.List

Area is property of your OrderViewModel, but not List<OrderViewModel>.

and you are actually trying to do something like:

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

and you are trying to draw EnumDropDownlistFor myList.Area. Which is not EVER possible. because Area is not a property of Generic List

Sign up to request clarification or add additional context in comments.

2 Comments

but in that way getting Error Cannot implicitly convert type 'Cygnus.Global.ViewModels.OrderViewModel' to 'System.Collections.Generic.List<Cygnus.Global.ViewModels.OrderViewModel>' D:\CygnusDev\GDR\OST\OST\Cygnus.Website.Base\Controllers\OrderController.cs
Downvoter, you are welcome to comment here. Please point out the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.