2014-09-12 67 views
0

我遇到類似 的問題以下是代碼:發生類型爲'System.IO.DirectoryNotFoundException'的異常mscorlib.dll中,但在用戶代碼 這裏沒有處理的代碼是:類型System.IO.DirectoryNotFoundException「的異常出現在mscorlib.dll但在用戶代碼在mscorlib.dll中發生類型'System.IO.DirectoryNotFoundException'的異常,但未在用戶代碼中處理

[ValidateInput(false)] 
    [AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult Create(HttpPostedFileBase haberform) 
    { 
     NewsModel image = new NewsModel(); 
     image.Tarih = DateTime.Now; 
     image.Kategori=Convert.ToInt32(Request.Form["Kategori"]); 
     image.Baslik =Request.Form["Baslik"]; 
     image.Detay = Request.Form["Detay"]; 
     image.Foto = Path.GetExtension(haberform.FileName); 
     db.NewsModels.Add(image); 
     db.SaveChanges(); 
     string filePath = Path.Combine(HttpContext.Server.MapPath("../Content/images"), Path.GetFileName(image.id.ToString() + Path.GetExtension(haberform.FileName))); 
     haberform.SaveAs(filePath); 
     return RedirectToAction("Index"); 
    } 




    @using (Html.BeginForm("Create", "News", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
    @Html.AntiForgeryToken() 

    <div class="form-horizontal"> 
     <h4>NewsModel</h4> 
     <hr /> 
     @Html.ValidationSummary(true) 

     @*<div class="form-group"> 
      @Html.LabelFor(model => model.Tarih, new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.Tarih) 
       @Html.ValidationMessageFor(model => model.Tarih) 
      </div> 
     </div>*@ 

     <div class="form-group"> 
      @Html.LabelFor(model => model.Kategori, new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.Kategori) 
       @Html.ValidationMessageFor(model => model.Kategori) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(model => model.Baslik, new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.Baslik) 
       @Html.ValidationMessageFor(model => model.Baslik) 
      </div> 
     </div> 

     @*<div class="form-group"> 
      @Html.LabelFor(model => model.Foto, new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.(model => model.Foto) 
       @Html.ValidationMessageFor(model => model.Foto) 
      </div> 
     </div>*@ 


     <div class="form-group"> 
      <label for="file">Upload Image:</label> 
      <div class="col-md-10"> 
       <input name="haberform" type="file" /> 
       </div> 
      </div> 




      <div class="form-group"> 
       @Html.LabelFor(model => model.Detay, new { @class = "control-label col-md-2" }) 
       <div class="col-md-10"> 
        @Html.EditorFor(model => model.Detay) 
        @Html.ValidationMessageFor(model => model.Detay) 
       </div> 
      </div> 

      <div class="form-group"> 
       <div class="col-md-offset-2 col-md-10"> 
        <input type="submit" value="Create" class="btn btn-default" /> 
       </div> 
      </div> 
     </div> 
} 

回答

0

及其與

解決沒有處理
@"~/Content/images" 
相關問題