本地主机下添加新项到数据库时(localHost down when adding new item

2019-10-28 12:44发布

我已经看到了怪异的事情在我的生活中,我: Controller, EF Auto-generated Model And a view一个物品系统。 在该系统中,我有一个动作添加了一篇文章,它看起来像在浏览器中:

中的代码,所述控制器:

[HttpPost]
public ActionResult AddArticle(NewsData art, HttpPostedFileBase file)
{

   if (file != null)
   {
       string pic = Path.GetFileName(file.FileName);
       string paths = Path.Combine(Server.MapPath("~/NewsPhotos/{0}"), pic);
       // file is uploaded
       file.SaveAs(paths);
       ViewBag.Path = String.Format("~/NewsPhotos/{0}", pic);
   }
   else if (file == null)
   {
       file.Equals("~/NewsPhotos/default.png");
       ViewBag.Path = String.Format("~/NewsPhotos/default.png");
   }

   using (MatrodyEntities db = new MatrodyEntities())
   {
       db.NewsData.Add(art);
       db.SaveChanges();
       var ArticleID = art.ArticleID;
   }
   return View("Article", art);
}

代码在视图中:

@using (Html.BeginForm("AddArticle", "Article", FormMethod.Post))
{
    @Html.AntiForgeryToken()

<div class="form-horizontal">
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <div class="form-group">
        @Html.LabelFor(model => model.ArticleTitle, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ArticleTitle, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ArticleTitle, "", new { @class = "text-danger" })
        </div>
    </div>
    <label for="file">Cover photo:</label>
    <input type="file" name="file" id="file" style="width: 100%;" />
    <h5>
        <i class="fa fa-link" aria-hidden="true"></i>
    </h5>
    <div class="form-group">
        <label class="col-md-4 control-label"> Description </label>
        <div class="col-md-12">
            <div class="input-group">
                @Html.TextAreaFor(m => m.ArticleText, new { rows = "20", style = "resize:none;width:400px;", placeholder = Html.DisplayNameFor(m => m.ArticleText), @class = "form-control col-12", id = "editor" })
                @Html.ValidationMessageFor(model => model.ArticleText, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>

    <script>
        CKEDITOR.replace('editor');
    </script>

    <div class="form-group">
        <input type="submit" value="Add" class="btn btn-outline-info col-4" />
    </div>


</div>

问题是,当我添加按钮单击本地主机负载了一会儿,然后它给了我这样的:

我敢肯定,本地主机宕机,因为当我重新载入页面或当我去到另一个页面不响应

我使用的视图页面CKEDITOR为model.articleText和HttpPostedFileBase编辑器来获取该没有提到在数据库中的文章一coverPhoto

我想知道为什么本地主机宕机,当我点击添加,以及如何解决它

文章来源: localHost down when adding new item to the database