arlen
arlen

Reputation: 1065

Redirecting to different Views in MVC

I have a couple of HTML files and I want to include them in my MVC project. I want to get the result as follows:

www.Test.com/Products/

www.Test.com/Products/Drinking/
www.Test.com/Products/Drinking/Product1
www.Test.com/Products/Drinking/Product2
www.Test.com/Products/Drinking/Product3


www.Test.com/Products/Cleaning/
www.Test.com/Products/Cleaning/Product1
www.Test.com/Products/Cleaning/Product2
www.Test.com/Products/Cleaning/Product3

www.Test.com/Products/SkinCare/
www.Test.com/Products/SkinCare/Product1
www.Test.com/Products/SkinCare/Product2
www.Test.com/Products/SkinCare/Product3

What is the best way to create my controller and how to put my files in nested views? or any other solution?

Upvotes: 0

Views: 93

Answers (2)

twaldron
twaldron

Reputation: 2752

Products could be your controller Drinking, Cleaning, and SkinCare could be actions with product1 product2 product3 being the id passed to the action.

Then return which ever view you want based on the productId. Or create a strongly typed view based on a class called Product and Pass the product object to the view.

   public class ProductsController : Contoller
   {
       public ActionResult Cleaning(string id)
       {
            Product p = new Product();
            //create the product based on the id

           return view(p);

        }

    }

or return a specific view name

return view("Product1");

or for a strongly typed view

return view("Product1",p);

Upvotes: 1

Aji
Aji

Reputation: 25

The [ASP] framework itself should take care of the routing for you. Models, Controllers and Views should all follow a specific naming convention which should then result in the correct URLs.

Upvotes: 0

Related Questions