Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>

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;
SQL
[Route("postID-{id}")]
public ActionResult Index(int? id)
{
    Post post = null;

    if (id != null)
        post = PostService.GetPostById((int)id);

    return View(post);
}

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())

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
Posted
Updated 15-Feb-15 5:55am
v2

1 solution

The answer turned out to be very simple.
SQL
@foreach (var item in Model.PostFeatureList)
{
     @Html.ActionLink((string)@item.Title, "Index", "Article");
     @Html.Raw(@item.Teaser)
}

The router appends "Controller" on the Controller parameter in ActionLink so by removing the "Controller" portion it worked.

Learning...baby steps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900