【发布时间】:2021-11-16 09:41:57
【问题描述】:
抱歉,我是 ASP.NET MVC 的新手,我正在开发一个 Web 应用程序,该应用程序部分由其他无法提供帮助的人完成。我有一个编辑新闻项目的视图,如下所示:
我要做的是删除“内容”部分并将其替换为“新闻内容”部分。
它似乎显示了来自 SQL 数据库的正确数据,但我无法让它显示 HTML 编辑器。这个新部分的数据来自一个名为 NewsArtical.cs 的链接 SQL 表
这是我的代码:
型号:
public partial class News
{
public int ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public System.DateTime Date { get; set; }
public Nullable<System.DateTime> LastModified { get; set; }
public virtual NewsArtical NewsArtical { get; set; }
}
public partial class NewsArtical
{
public int ID { get; set; }
public string NewsContent { get; set; }
public virtual News News { get; set; }
}
NewsController:
// GET: News/Edit/5
public async Task<ActionResult> Edit(int? id)
{
if (id == null)
{
return RedirectToRecordNotFound();
//return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
News news = await _entities.News.FindAsync(id);
if (news == null)
{
return HttpNotFound();
}
return View(news);
}
查看Edit.cshtml:
@model CELIntranet.Models.News
@{
ViewBag.Title = string.Format("Edit News Article: {0}", Model.ID);
}
@Html.Partial("_ContentToolbarPartial", (object)@ViewBag.Title)
<body>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control focusme" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control", cols = 80, rows = 10 } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.NewsArtical.NewsContent, htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.NewsArtical.NewsContent, new { htmlAttributes = new { @class = "form-control", cols = 80, rows = 10 } })
@Html.ValidationMessageFor(model => model.NewsArtical.NewsContent, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Date, htmlAttributes: new { @class = "control-label" })
@Html.TextBox("Date", Model.Date.ToShortDateString(), (object)new { @class = "form-control form-control-minwidth" })
@Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.LastModified, htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.LastModified, new { htmlAttributes = new { @class = "form-control form-control-minwidth", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.LastModified, "", new { @class = "text-danger" })
</div>
<br />
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary btn-sm" />
<input type="button" value="Cancel" class="btn btn-default btn-sm" onclick="history.go(-1);return true;" />
</div>
}
</body>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/summernote")
<script type="text/javascript">
$(function () {
$("#Description").summernote({
minHeight: 200
});
$('#Date').datetimepicker({
format: 'DD/MM/YYYY',
showClose: true,
showClear: true,
toolbarPlacement: 'top'
});
});
</script>
}
非常感谢任何帮助。
谢谢。
【问题讨论】:
标签: c# asp.net-mvc