【发布时间】:2012-08-02 06:22:25
【问题描述】:
我的项目结构是这样的:
- 控制器/ArticlesController.cs
- 控制器/CommentsController.cs
- Views/Articles/Read.aspx
Read.aspx 带一个参数say“output”,就是文章的详细信息,通过id和它的cmets,从ArticlesController.cs传递过来的
现在我想写然后阅读评论:: write() & Read() 函数在CommentsController.cs
为了阅读带有 cmets 的文章,我想通过传递来自 CommentsController.cs 的输出参数从 CommentsController.cs 调用 Views/Articles/Read.aspx
我该怎么做?
更新
代码在这里:
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的方法。是这样吗?
标签: c# asp.net-mvc