Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to use index.html from mvc

When I loaded up my new website I have some of it using MVC and the other half using static pages.

The first page should be index.html

However when I go to http://domain, it goes directly in to the MVC controller.

It does not go to index.html, even though I have IIS pointing to this page, it might be due to the fact that I am using wild cards from within IIS, as detailed in my blog http://www.bryanavery.co.uk/post/2009/07/02/Deploying-MVC-on-IIS-6.aspx

But I need the first page to go to index.html when I select http://domain

Any ideas?

like image 382
Coppermill Avatar asked Nov 11 '09 12:11

Coppermill


People also ask

How add HTML to MVC?

There are two ways in MVC to create custom Html helpers as below. We can create our own HTML helper by writing extension method for HTML helper class. These helpers are available to Helper property of class and you can use then just like inbuilt helpers. Add new class in MVC application and give it meaningful name.

What is index method MVC?

The Index() method is an example of a controller action. A controller action must be a public method of a controller class. C# methods, by default, are private methods.

Does MVC use HTML?

It is not mandatory to use HTML Helper classes for building an ASP.NET MVC application. We can build an ASP.NET MVC application without using them, but HTML Helpers helps in the rapid development of a view.

How to create Index view using loadhtmlcontroller?

Step 1: Right click on the "Controllers" folder and add "LoadHtml" controller. Copy and paste the following code. Step 2: Right click on the "Index" action method in the "LoadHtmlController" and add "Index" view. Copy and paste the following code. Step 3: Right click on the project and create html file "add.html". Copy and paste the following code.

How to load an HTML page in ASP NET MVC view?

In this example, I will show you how to load an html page in asp.net MVC view. You can call an html page from your view using Html.Action helper method. In controller action you can return an HTML file by using FilePathResult; it will return the content of the file to the response.

How to generate PDF through HTML content in MVC?

For instance, if you want to generate PDF through HTML content you need to get the MVC View and Layout DOM content. Here you go with the step by step process to get the DOM content. This is the _Layout.cshtml file, which is available in Shared directory. Find the below screenshot for reference. This is like the master page.

Why should I use ASP NET MVC core for forms?

ASP.NET MVC Core will bind the form data to your model automatically. This also means we won’t find ourselves constantly updating the Index action every time we need to handle another value submitted via the form.


Video Answer


2 Answers

You could direct the path to a controller action and return the file like this:

public ActionResult Index()
{
    return File("index.html", "text/html");
}
like image 91
Paul Avatar answered Oct 09 '22 18:10

Paul


Tell the routing engine to ignore index.html:

routes.IgnoreRoute("index.html");
like image 28
PatrickSteele Avatar answered Oct 09 '22 18:10

PatrickSteele