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?
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.
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.
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.
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.
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.
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.
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.
You could direct the path to a controller action and return the file like this:
public ActionResult Index()
{
return File("index.html", "text/html");
}
Tell the routing engine to ignore index.html:
routes.IgnoreRoute("index.html");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With