繁体   English   中英

ASP.NET Core Tag助手和导致的HTML差异

[英]ASP.NET Core Tag helpers and resulted HTML difference

抱歉,标题不清晰,但不知道如何指定标题,请随时编辑我的问题。

我设法在Razor Pages中编写了与给定代码等效的代码:

我的标记:

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

产生以下HTML:

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

第二块标记:

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

产生以下HTML:

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

我想知道的是:除了生成的URL不同之外,两者之间有什么区别?URL中不同的部分是什么意思?

编辑

这是我的Startup课程:

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();
    }
}

我很确定,Html.ActionLink无法与Razor Pages一起正常使用,因为它是根据路由信息生成链接的,并且与控制器和操作有关。 剃刀页面没有控制器和动作。 因此,AnchorTagHelper在这里将发挥最佳作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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