Я пытаюсь создать новый продукт, но выдает ошибку на
. Это не тип IEnumerable
Я проверяю - меняю метод PostПолучить для просмотра, если данные перекрестные URL или нет, и получить данные в порядке
Это контроллер:
public ActionResult Ajouter()
{
db = new IdentityDBEntities2();
ViewBag.categ = new SelectList(db.Categories, "Id", "libelle");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
[Route("Create")]
public ActionResult Ajouter([Bind(Include = "Ida,description,image,Userid,Idc,titre")] Article article, HttpPostedFileBase postedFile)
{
try
{
if (ModelState.IsValid)
{
if (postedFile != null)
{
db = new IdentityDBEntities2();
article.image = Convert.ToString(postedFile.ContentLength);
postedFile.InputStream.Read(System.Text.Encoding.Unicode.GetBytes(article.image), 0, postedFile.ContentLength);
string fileName = System.IO.Path.GetFileName(postedFile.FileName);
string FilePath = "~/Content/img/" + fileName;
postedFile.SaveAs(Server.MapPath(FilePath));
article.UserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
article.Idc = Convert.ToInt32(Request["Cab"]);
article.image = fileName;
db.Articles.Add(article);
ViewBag.categ = new SelectList(db.Categories, "Id", "libelle");
db.SaveChanges();
return RedirectToAction("Index");
}
}
else return View(article);
}
catch
{
return View();
}
return View();
}
- И это Dropdown в представлении:
@Html.DropDownList("categ", null, "-- Select Category -- ", new { id = "subCategory" })
Я уже изменяю содержимое выпадающего меню на
@Html.DropDownList("categ",(IEnumerable<SelectListItem>)ViewBag.Cab, "-- Select Category -- ", new { id = "subCategory" })
Но не работает.спасибо