I need to set a new landing page for my application. For now it is landing on the standard Index.cshtml inside of the Home folder inside of the Views folder. I want my new landing page to be from this directory:
Views/Welcome/Index.cshtml
The error I'm getting says: InvalidOperationException: RenderBody has not been called for the page at '/Views/Welcome/Index.cshtml'. To ignore call IgnoreBody();
I have made the following changes so far in my startup.cs file:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.Configure<RazorViewEngineOptions>(o =>
{
o.ViewLocationFormats.Clear();
o.ViewLocationForms.Add("/Views/Welcome/Index" + RazorViewEngine.ViewExtension);
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Welcome}/{action=Index}/{id?}");
});
endpoints.MapFallbackToController("Index", "Welcome");
}
My View:
@{
ViewData["Title"] = "Index";
}
//html
//jQuery
I haven't found any resources online on how to accomplish this when using MVC.
Thanks!