Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

c# - How to use something other than "Index" as the default controller view in ASP.NET Core MVC?

I have an ASP.Net MVC/Razor app. The default view is always assumed to be Index.html, and I would like to know where that is set and whether that can be changed. I do not like having dozens of files all named Index.cshtml, and would prefer my default files to be named something else.

Is is possible to change this default? I know that I can just set a different view path when Index is called in the controller, but would like something less manual.

question from:https://stackoverflow.com/questions/65623211/how-to-use-something-other-than-index-as-the-default-controller-view-in-asp-ne

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just change your route template:

app.UseEndpoints(endpoints =>
{               
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=OtherPage}/{id?}"); 
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...