Reputation: 888
I have a @Html.ActionLink in a .cshtml which is in my CustomerOrder folder, but I want point to an action method in a different folder.
My actionlink is:
@Html.ActionLink("Order", "/Products/ProductList", new { id = Model.ID }, new { @class = "link-button btn-primary" })
I'm getting an HTTP Error 404.0 - Not Found error and this is the URL:
http://localhost:63549/CustomerOrder/Products/ProductList/1
I want the resulting view to be:
http://localhost:63549/Products/ProductList/1
Upvotes: 0
Views: 1997
Reputation: 62498
You are specifying the controller and action both in the same parameter using the overload which takes just action method name which is not correct in this case as you want to call action method on a different controller class.
You actually need to specify action method name and controller name using the following overload method:
@Html.ActionLink("Order", "ProductList","Products",
new { id = Model.ID },
new { @class = "link-button btn-primary" })
and in controller class you will have to add an action method for it:
public class ProductsController : Controller
{
................
................
// other action methods here
public ActionResult ProductsList(int id)
{
// your code goes here and finaly returns view
// var model = new Model();
return View(model)
}
}
Upvotes: 2