2
I have always used ASP.NET MVC 4 and now I am learning ASP.NET Core in version 2.2, I am doing some tests and I noticed that the routing is not working.
I am using the standard design that is already configured.
Within Startup.cs
configure the route as follows:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
});
}
Then insert the following on the page index.cshtml
:
@Html.ActionLink("Link para a Action About no mesmo controlador", "About")
But when I see the result in View Index.cshml
is returned to me:
I’m doing something wrong?
Are you using "normal" ASP.NET with . NET Core? O.o
– Jéf Bueno
ASP.NET Core 2.2
– Leonardo Bonetti
In Asp.net core you have a more "clean" way of creating links <a Asp-action="About">Link to Action About in the same controller</a> .
– António Campos
Another important thing on. net core (which was already in MVC 4) is to respect conventions (code rules), the compiler/interpreter respects those rules when interpreting your code, I mention this because in the structure of your project some of the folders of the MVC convention are missing... for Actionlink the controller and the action must exist and respect the convention to be recognized as such. Only then when generating the link the . net core will know the correct route to generate the <a href=...
– António Campos