本文介绍了如何更正AddToPost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在创建博客时遇到问题。
问题在于PostsController代码的更新部分中的AddToPost,它无法识别AddToPost代码。我得到一个缺失的指令或汇编参考,有没有人有任何想法。我确实尝试用Add替换AddToPost,我得到了同样的错误,有什么建议吗?
代码如下:
I am having a problem creating a blog.
The problem is with the AddToPost in the update part of the PostsController code, it is not recognizing the AddToPost Code. I am getting a missing directive or assembly reference, does anyone have any ideas. I did try just replacing the AddToPost with Add, I got the same error, any suggestions?
The code is as follows:
public ActionResult Update(int? id, string title, string body, DateTime datetime, string tags)
{
if (!IsAdmin)
{
return RedirectToAction("Index");
}
Post post = GetPost(id);
post.Title = title;
post.Body = body;
post.DateTime = datetime;
post.Tags.Clear();
tags = tags ?? string.Empty;
string[] tagNames = tags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string tagName in tagNames)
{
post.Tags.Add(GetTag(tagName));
}
if (!id.HasValue)
{
model.AddToPosts(post);
}
model.SaveChanges();
return RedirectToAction("Details", new { id = post.ID });
}
谢谢,再次期待尽快收到您的回复。
Thanks, again look forward to hearing from you soon.
推荐答案
这篇关于如何更正AddToPost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!