mscorlib.dll中出现“System.IO.DirectoryNotFoundException”类型的异常,但未在用户代码中处理

时间:2014-09-12 14:06:45

标签: asp.net-mvc

我有一个问题 这是代码:类型' System.IO.DirectoryNotFoundException'的例外。发生在mscorlib.dll但未在用户代码中处理 这是代码:类型' System.IO.DirectoryNotFoundException'的例外。发生在mscorlib.dll中但未在用户代码中处理

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

1 个答案:

答案 0 :(得分:0)

解决了
@"~/Content/images"