在我的主页面上,我有一个文章项目列表,其中包含每个项目的链接,链接将我带到ArticleController,我可以根据我作为参数传递的postID查找文章。
On my main page I have a list of Article items with a link to each item, the link take me to an ArticleController where I can look up the Article based on the postID I have passed as a parameter.
@foreach (var item in Model.PostFeatureList) { @Html.ActionLink((string)@item.Title, "Index", "ArticleController"); @Html.Raw(@item.Teaser) }生成的是什么;
What's produced is;
<a postid="101" href="/ArticleController">EEPROM Programmer 2 of 4 - Communications</a>哪个在假设Index操作是默认操作,我的思路在本地机器上调试是正确的。 然后在ArticleController.Index我有;
Which in my mind is correct for debugging on my local machine, assuming that Index action is the default action. Then in ArticleController.Index I have;
[Route("postID-{id}")] public ActionResult Index(int? id) { Post post = null; if (id != null) post = PostService.GetPostById((int)id); return View(post); }现在问题点击我得到的链接; HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址并确保拼写正确。 请求的网址:/ ArticleController 在我的主叫视图中;
So now the question when I click on the link I get; HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /ArticleController In the calling view I have;
@using (Html.BeginForm())我需要什么吗在BeginForm中告诉它我想要路由到哪里或者是否有其他地方我需要让路由器知道我想要这样做? 谢谢Y 'all
Do I need something in the BeginForm to tell it where I want to route to or is there some other place I need to let the router know that I want to do this? Thanks Y'all
推荐答案答案结果非常简单。 The answer turned out to be very simple. @foreach (var item in Model.PostFeatureList) { @Html.ActionLink((string)@item.Title, "Index", "Article"); @Html.Raw(@item.Teaser) }
路由器在ActionLink的Controller参数上添加Controller,因此删除它工作的Controller部分。 学习......宝贝步骤。
The router appends "Controller" on the Controller parameter in ActionLink so by removing the "Controller" portion it worked. Learning...baby steps.
更多推荐
MVC5路由问题
发布评论