简体   繁体   中英

ASP.NET Core Tag helpers and resulted HTML difference

Apologies for unclear title, but didn't know how to specify it, please, feel free to edit my question.

I managed to write equivalent code to given one in Razor Pages:

My markup:

<a asp-page="./Index" asp-route-id="@Model.InstructorID" asp-route-courseID="@item.CourseID">Select</a>

Which results in following HTML:

<a href="/Instructors/2?courseID=1045">Select</a>

Second piece of markup:

@Html.ActionLink("Select", "OnGetAsync", new { courseID = item.CourseID })

Which results in following HTML:

<a href="/Instructors/2?courseID=1045&amp;action=OnGetAsync">Select</a>

What I would like to know: what is the difference between the two, except different URL generated and what does the differing part in URL mean?

EDIT

Here's my Startup class:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<Data.SchoolContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ContosoUniversityConnectionString")));

        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
        }

        app.UseStaticFiles();

        app.UseMvc();
    }
}

I'm pretty sure, the Html.ActionLink will not work properly with Razor Pages, because it is generating the link out of route information and relates to controllers and actions. Razor Pages don't have controllers and actions. So the AnchorTagHelper will work best here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM