localHost down when adding new item to the database

对着背影说爱祢 提交于 2019-12-11 17:38:53

问题


I've been seeing the weirdest thing in my life I have: Controller, EF Auto-generated Model And a view for an articles system. in that system, I have an action for adding an article and it looks like that in the browser :

the code in the Controller :

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

code in the view :

@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>

The problem is that when I click on add button the localhost load for a while and then it gives me this :

I'm pretty sure that the localhost is down because when I reload the page or when I go to another pages it doesn't respond

I'm using ckEditor in the view page as an editor for model.articleText and HttpPostedFileBase to get a coverPhoto for the article that IS NOT MENTIONED IN THE DATABASE

I want to know why the localhost is down when I click on add and how to fix it

来源:https://stackoverflow.com/questions/55410061/localhost-down-when-adding-new-item-to-the-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!