0

On my MVC project I have to incorporate 40 static pages.
I want these pages to use the Layout page.
What is the best way to do that?
I know this question was asked before but I didn't find any good answer.
Any advise?

2 Answers 2

1

I don't relly know ASP, but I try to give a generic answer.

So I think if you have a lot of similar static pages, somehow you could make a controller action that handles all these pages. For example the action gets the name of the page as a path variable in the URL, and return the view according to that.

But if that is not possible in the language you are using, you can just make simple separate actions for these pages. Maybe you could group the related ones into the same controller, so you would have a few controllers that handle these pages, and they are not stuffed in one controller.

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

1 Comment

Thank you, I was thinking about this solution, but I wanted to know if there is any "nicer" and simpler solution.
0

Basically the solution is very simple, you have to create views for you static HTML (cshtml), then you should add a Route to your Route.Config like this:

        routes.MapRoute(
        "OrdeForm",
        "OrderForm/{file}",
        new { controller = "MyController", action = "Page", file} = "" }
    );

Where "File" is a dynamic parameter that gets the View name from the URL and renders the right View.

The global controller should be something like this:

public class OrderFormController : Controller
    {
        public ActionResult Index(string file)
        {
            return View(file);
        }
    }

That works perfectly! Thank you @Erik Philips for the excellant answer!

Comments

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.