0

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

enter image description here

1 Answer 1

2

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

}
Sign up to request clarification or add additional context in comments.

1 Comment

I had the controller class. but not the quite obvious syntax of the actionlink - I did not see it...So thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.