我使用的是ASP.NETMVC,我有一个模型类,它表示与一个实体关联但由另一个实体创建的数据集。例如,给定以下ViewModels,
public class User {
public int UserId { get; set; }
public IEnumerable<NewsComment> Comments { get; set; }
}
public class News {
public int NewsId { get; set; }
public string News { get; set; }
public IEnumerable<NewsComment> Comments { get; set; }
}
public class NewsComment {
public int NewsCommentId { get; set; }
public string Comment { get; set; }
public int NewsId { get; set; }
public int UserId { get; set; }
}
public class NewsController : Controller
{
public ActionResult Index()
{
return View(ListAllNews());
}
public ActionResult Detail(int newsId)
{
return View(GetNewsItem(newsId));
}
}
public class NewsCommentController : Controller
{
[AcceptVerbs(HttpVerbs.Post)]
public void Create()
{
int newsId = Request["news_id"];
int userId = Request["user_id"];
string comment = Request["comment"];
SaveNewsComment(newsId, userId, comment);
return RedirectToAction("Detail","News",new { newsId = newsId });
}
}
如果我只在News/Detail视图或User/Detail视图上显示评论,并且评论发布在News/Detail视图上,那么
-
-
NewsCommentController是否应该只有一个创建操作,该操作在方法完成后从调用并重定向回NewsController/Detail操作?
-
我应该用吗
RenderAction
从NewsCommentController中列出我的评论?
-