2014-03-27 33 views
1

我在堆栈溢出中找到了关于此问题的多篇文章,但没有找到解决我所遇到的问题的答案。没有类型为'IEnumerable <SelectListItem>'的ViewData项的关键字'IdJournal'

我有,从表中显示数据库日志的项目标签一个下拉列表视图:杂志:ID,标签 下面是这个视图的代码:

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @enctype = "multipart/form-data" })) 
        {    
     <input style="margin-left:40px;cursor:pointer;" type="file" name="file" id="upload"/> 
     <input type="text" name="journal" value="test"/> 

     <input type="submit" style="margin-left:40px;cursor:pointer;" id="load" value="Upload"/> 

        @Html.DropDownList("IdJournal") 
        } 

我的控制器:

[HttpPost] 
    public ActionResult Index(HttpPostedFileBase file, string journal, long IdJournal) 
    { 

     ScanITAPP.Service.ImageRender service = new Service.ImageRender(); 
     service.UploadImageToDB(file, journal, IdJournal); 



     return View(); 
    } 

    public ActionResult Form() 
    { 
     return PartialView("Form"); 
    } 

    //DropdownList 
    public ActionResult Index() 
    { 
     var db = new Bd_scanitEntities(); 
     IEnumerable<SelectListItem> items = db.JournalSet 
      .Select(c => new SelectListItem 
      { 
       Value = c.Id.ToString(), 
       Text = c.label 
      }); 
     ViewBag.IdJournal = items; 
     //ViewData["IdJournal"] = items; 

     return View(); 
    } 

的代码上传和图像,并将其关联到“日志”,执行的代码后,我获得与Journal_id形象在我Dtabse但是却抛出一个错误:有类型的无ViewData的项目'IEnumerable'具有关键'Id'。我不知道有什么问题请帮助我。

回答

1

我编辑我的控制器方法

[HttpPost] 
public ActionResult Index(HttpPostedFileBase file, string journal, long IdJournal) 
{  
    var db = new Bd_scanitEntities(); 
    IEnumerable<SelectListItem> items = db.JournalSet 
     .Select(c => new SelectListItem 
     { 
      Value = c.Id.ToString(), 
      Text = c.label 
     }); 
    ViewBag.IdJournal = items; 

    ScanITAPP.Service.ImageRender service = new Service.ImageRender(); 
    service.UploadImageToDB(file, journal, IdJournal); 



    return View(); 
} 
+0

这就是好,你自己解决.. :) +1 –

+0

也提到解决这个问题是什么改变你做 –

相关问题