我对 asp net Mvc 非常陌生,我正在尝试在 mvc 4 中创建一个简单的论坛。我可以创建和列出线程和帖子,但我似乎无法弄清楚如何将新帖子添加到现有线程。换句话说,我希望能够将多个帖子连接到特定的ThreadId
.
那么实现这一点的最佳方法是什么,我应该将一个值传递@ActionLink
给我PostController Create method
的ThreadId
值吗?或者我可以在我的 PostController 中以某种方式专门处理这个问题吗?非常感谢任何代码示例或提示。
我有以下课程:
public class Thread
{
public int ThreadId { get; set; }
public DateTime ? PostDate { get; set; }
public string ThreadText { get; set; }
public string ThreadTitle { get; set; }
public virtual UserProfile UserProfile { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string PostTitle { get; set;}
public string PostText { get; set; }
public DateTime ? PostDate { get; set; }
public virtual UserProfile UserProfile { get; set; }
public virtual Thread Thread { get; set; }
[System.ComponentModel.DataAnnotations.Schema.ForeignKey("Thread")]
public int ThreadId { get; set; }
}