这是我的控制器
[ActionName("Articles")]
public ActionResult ArticleSubmitted()
{
var articles = db.Articles.ToList()
.OrderByDescending(e => e.PostedDate)
.Select(e => new ArticleViewModel()
{
ArticleId = e.ArticleId,
Title = e.Title,
PostedByName = e.ApplicationUser.UserName,
PostedDate = e.PostedDate,
PageContent = e.PageContent
});
return View(articles);
}
我想要操作方法名称但是为了工作, 我必须将最后一行改为:
return View(ArticleSubmitted);
然后它会显示正确的动作名称,但在那种情况下,我无法传递文章进行查看,以便如何更改它以返回文章。
答案 0 :(得分:0)
使用ViewData.Model
将您的模型传递给View,如下所示:
[ActionName("Articles")]
public ActionResult ArticleSubmitted()
{
var articles = db.Articles.ToList()
.OrderByDescending(e => e.PostedDate)
.Select(e => new ArticleViewModel()
{
ArticleId = e.ArticleId,
Title = e.Title,
PostedByName = e.ApplicationUser.UserName,
PostedDate = e.PostedDate,
PageContent = e.PageContent
});
ViewData.Model = articles;
return View(ArticleSubmitted);
}
答案 1 :(得分:0)
您应该使用此重载视图,我认为它应该可以工作:
return View("ArticleSubmitted", articles);
此外,如果您从其他地方调用该特定操作方法,则将操作方法名称从ArticleSubmitted更改为文章,如下所示:
@Html.ActionLink("name of text", "Articles", "Controller name")