【问题标题】:An exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll but was not handled in user codemscorlib.dll 中出现“System.IO.DirectoryNotFoundException”类型的异常,但未在用户代码中处理
【发布时间】:2014-09-12 14:06:44
【问题描述】:

我有一个问题 以下是代码:mscorlib.dll 中发生了“System.IO.DirectoryNotFoundException”类型的异常,但未在用户代码中处理 下面是代码: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>
}

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    解决了

    @"~/Content/images"
    

    【讨论】:

      猜你喜欢
      • 2015-05-12
      • 1970-01-01
      • 2019-04-29
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多