【发布时间】:2020-02-17 01:12:48
【问题描述】:
我正在尝试替换帖子正文中的内容,我正在使用所见即所得的编辑器。我正在输入文本“占位符”并尝试用我的控制器中的 ASP.NET Identity 用户数据替换它。
我有一个 ASP.NET Identity 的扩展方法:
public static string GetUserFirstName(this IIdentity identity)
{
var db = ApplicationDbContext.Create();
var user = db.Users.FirstOrDefault(u => u.UserName.Equals(identity.Name));
return user != null ? user.FirstName : String.Empty;
}
这是我在控制器中的创建操作
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Image,TypeId,ModalName,Title,Description,Body,CreatedAt")] Document document, HttpPostedFileBase Image)
{
if (ModelState.IsValid)
{
// set timestamp
document.CreatedAt = DateTime.Now;
if (!string.IsNullOrEmpty(document.Body))
{
document.Body.ToLower().Replace("Placeholder", User.Identity.Name);
}
//extract first three characters of the document title as the Id for the modal pop up
document.ModalName = document.Title.Substring(0, 3);
db.Documents.Add(document);
db.SaveChanges();
// redirect to index page
return RedirectToAction("Index");
}
ViewBag.TypeId = new SelectList(db.DocumentTypes, "Id", "Type", document.TypeId);
return View(document);
}
这是风景
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="@item.Title" aria-hidden="true" id="@item.ModalName">
<div class="modal-dialog modal-lg">
<div class="modal-content">
@Html.Raw(item.Body)
</div>
</div>
</div>
【问题讨论】:
标签: c# asp.net asp.net-mvc razor