Here is my code for my AddNewProductViewModel
using AccessorizeForLess.Data;
using System.Collections.Generic;
using System.ComponentModel.DataA
I solved the issue (thanks to everyone for the tips). This is for anyone who may be having issues like I was.
I changed my Create method to look like so:
// GET: /Products/Create
public ActionResult Create()
{
var p = new AddNewProductViewModel();
p.Categories = entities.ProductCategories.ToList();
return View(p);
}
My AddNewProductViewModel looks like so:
using AccessorizeForLess.Data;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web;
namespace AccessorizeForLess.ViewModels
{
public class AddNewProductViewModel
{
public string Name { get; set; }
[DataType(DataType.MultilineText)]
public string Description { get; set; }
public decimal Price { get; set; }
public string AltText { get; set; }
public int Quantity { get; set; }
public HttpPostedFileBase Image { get; set; }
public int SelectedCategoryId {get;set;}
public List Categories { get; set; }
public ProductCategory Category { get; set; }
}
}
The in my view:
@Html.LabelFor(model => model.SelectedCategoryId, "Category",new { @class = "control-label col-md-2" })
@Html.DropDownListFor(model => model.SelectedCategoryId, new SelectList(Model.Categories, "CategoryId", "CategoryName"), "- Please Select -")
@Html.ValidationMessageFor(model => model.SelectedCategoryId)
Thanks for the help everyone :)