我的项目结构如下:
- Controllers/ArticlesController.cs
- Controllers/CommentsController.cs
- Views/Articles/Read.aspx
Read.aspx 接收一个参数,“output”,它包含文章 id 和评论,是通过 ArticlesController.cs
传递过来的。
现在我想要在 CommentsController.cs
中编写并读取评论的write()
和 Read()
函数。
为了读取带有其评论的文章,我想从 CommentsController.cs
中调用 Views/Articles/Read.aspx
并传递从 CommentsController.cs
中获取的输出参数。
我该怎么做?
更新
代码如下:
public class CommentsController : AppController
{
public ActionResult write()
{
//some code
commentRepository.Add(comment);
commentRepository.Save();
//works fine till here, Data saved in db
return RedirectToAction("Read", new { article = comment.article_id });
}
public ActionResult Read(int article)
{
ArticleRepository ar = new ArticleRepository();
var output = ar.Find(article);
//Now I want to redirect to Articles/Read.aspx with output parameter.
return View("Articles/Read", new { article = comment.article_id });
}
}
public class ArticlesController : AppController
{
public ActionResult Read(int article)
{
var output = articleRepository.Find(article);
//This Displays article data in Articles/Read.aspx
return View(output);
}
}
ArticlesController
调用CommentsController
中的一个方法,是这样吗? - Andre Calil