我一直看到自己一生中最奇怪的事情:Controller, EF Auto-generated Model And a view
用于文章系统。
在该系统中,我有一个添加文章的操作,在浏览器中看起来像这样:
https://i.stack.imgur.com/w3IkJ.png
控制器中的代码:
[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>
问题是,当我单击添加按钮时,本地主机加载了一段时间,然后它给了我:
https://i.stack.imgur.com/9Ml8t.png
我非常确定本地主机已关闭,因为当我重新加载页面或转到其他页面时,它不会响应
我正在视图页面中使用ckEditor作为model.articleText的编辑器 和HttpPostedFileBase获取数据库中未提及的文章的CoverPhoto
我想知道为什么当我单击添加时如何关闭本地主机
注意:我之前曾问过这个问题,但没有人回答我,所以我需要尽快回答。谢谢。