Làm cách nào để chuyển tham số tới thẻ liên kết trong URL?

Polachan, các tham số liên kết (neo) được truyền vào URL (HTTP GET). Mã của bạn chưa hoàn chỉnh nên không thể đưa ra giải pháp chính xác để giải quyết vấn đề của bạn. Ví dụ: bạn đã đăng nội dung này trong diễn đàn JavaScript nhưng đang hiển thị ASP. NET Core cú pháp. Bạn đang cố gắng để AJAX không phô trương hoạt động?

href="/Home/[email protected]&[email protected]&[email protected]" 

Bạn cũng có thể sử dụng cú pháp trình trợ giúp thẻ tiêu chuẩn, giả sử đây là ứng dụng Core, được đề cập trong tài liệu xuất bản công khai. Giống như nhiều bài đăng của bạn, tôi khuyên bạn nên đọc tài liệu, nó thực sự hữu ích

Link

Bạn có thể tìm hiểu HTTP GET và POST tại mực sau

https. //www. w3schools. com/tags/ref_httpmethods. asp

Trình trợ giúp thẻ neo nhắm mục tiêu thẻ neo HTML (

<a asp-fragment="notes">Click</a>
3) được sử dụng để tạo liên kết tương đối từ các giá trị được chuyển đến các thuộc tính tùy chỉnh khác nhau. Nó cũng có thể được sử dụng để tạo URL tuyệt đối cho các tài nguyên bên ngoài

Vai trò của trình trợ giúp thẻ neo là tạo thuộc tính

<a asp-fragment="notes">Click</a>
4 từ các giá trị thông số được chuyển đến thuộc tính tùy chỉnh của nó. Do đó, nếu bạn cố gắng thêm thuộc tính
<a asp-fragment="notes">Click</a>
4 vào trình trợ giúp thẻ liên kết cũng như các giá trị cho thuộc tính tùy chỉnh, một ngoại lệ sẽ xuất hiện

Ngoại lệ hoạt động không hợp lệ. Không thể ghi đè thuộc tính 'href' cho

<a asp-fragment="notes">Click</a>
3. Một
<a asp-fragment="notes">Click</a>
3 có 'href' được chỉ định không được có các thuộc tính bắt đầu bằng 'asp-route-' hoặc 'asp-action', 'asp-controller', 'asp-area', 'asp-route', 'asp-protocol

Nếu không thể khớp một tuyến đường từ các giá trị được chuyển đến các thuộc tính taghelper, đầu ra cho thuộc tính

<a asp-fragment="notes">Click</a>
4 sẽ âm thầm trở lại một chuỗi trống

Thuộc tínhMô tả_______2_______9Tên của phương thức hành động trên bộ điều khiển MVC
<a asp-page="/page">Click</a>
01Nhiều giá trị tham số tuyến đường
<a asp-page="/page">Click</a>
1Tên của Khu vực
<a asp-page="/page">Click</a>
2Tên của bộ điều khiển MVC
<a asp-page="/page">Click</a>
32Đoạn trong URL
<a asp-page="/page">Click</a>
4Tên miền
<a asp-page="/page">Click</a>
53Trang Razor để liên kết đến
<a asp-page="/page">Click</a>
64Phương thức trình xử lý trang Razor để gọi_______9_______7Tên miền_______9_______53Tên của _______9, ft___p, v.v.8

ghi chú

  1. Nếu URL mục tiêu bao gồm nhiều , thì các giá trị của chúng có thể được đóng gói dưới dạng

    <a asp-page="/folder/index">Folder</a>
    
    0 và được chuyển đến thông số
    <a asp-page="/page">Click</a>
    
    0

    @{   
        var d = new Dictionary<string, string>
            {
               { "key1", "value1" },
               { "key2", "value2" }
            };
    }
    
    <a asp-all-route-data="d">Click</a>
    

    Nếu tuyến đường có tham số được xác định, trình trợ giúp thẻ neo sẽ xuất các giá trị dưới dạng phân đoạn URL.

    <a asp-page="/folder/index">Folder</a>
    
    2. Nếu không, các tham số tuyến đường sẽ được thêm vào URL dưới dạng giá trị chuỗi truy vấn.
    <a asp-page="/folder/index">Folder</a>
    
    3

  2. Đoạn là giá trị sau dấu thăng hoặc dấu thăng (

    <a asp-page="/folder/index">Folder</a>
    
    4) trong một URL được sử dụng để xác định phần được đặt tên của tài liệu. Tiêu đề "Ghi chú" ở trên có giá trị nhận dạng là "ghi chú" và có thể được tham chiếu trong URL bằng cách sử dụng trình trợ giúp thẻ liên kết như thế này

    <a asp-fragment="notes">Click</a>
    

    sản xuất HTML này.

    <a asp-page="/folder/index">Folder</a>
    
    5

  3. Đường dẫn đến trang Razor mục tiêu phải được cung cấp mà không có phần mở rộng tệp.

    <a asp-page="/folder/index">Folder</a>
    
    6 hàng đầu chỉ định một đường dẫn tuyệt đối. Nếu bạn bỏ qua nó, khung sẽ tìm một trang có liên quan đến trang hiện tại

    <a asp-page="/page">Click</a>
    

    Nếu không có tên trang hợp lệ nào được chỉ định, trình trợ giúp thẻ sẽ hiển thị thuộc tính

    <a asp-fragment="notes">Click</a>
    
    4 bằng một chuỗi trống. Nếu bạn muốn tạo liên kết đến trang mặc định trong một thư mục, bạn vẫn phải bao gồm tên tệp của trang mặc định

    <a asp-page="/folder/index">Folder</a>
    

    Điều này hiển thị là

    <a asp-page="/folder/index">Folder</a>
    
    8
    Trình trợ giúp thẻ sẽ tạo thuộc tính
    <a asp-fragment="notes">Click</a>
    
    4 có giá trị sẽ được lấy từ mẫu tuyến đường của trang được chỉ định

  4. Tên phương thức xử lý trang sẽ xuất hiện dưới dạng giá trị chuỗi truy vấn trừ khi nó được đưa vào làm tham số định tuyến cho trang đích

  5. Các trang dao cạo không hỗ trợ các tuyến đường được đặt tên. Tham số này sẽ chỉ được sử dụng cho các tuyến MVC

  6. Thuộc tính

    <a asp-page="/page">Click</a>
    
    9 cho phép bạn chỉ định giá trị cho một tham số dữ liệu tuyến đường. Tên tham số được thêm vào sau dấu gạch nối. Ở đây, tên tham số tuyến đường là "key1"
    ### Ambient Route Values 
    
    Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 
    
    1
    Điều này ám chỉ như
    ### Ambient Route Values 
    
    Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 
    
    2
    nếu tham số
    ### Ambient Route Values 
    
    Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 
    
    3 được xác định là một phần của mẫu tuyến đường của trang hoặc
    ### Ambient Route Values 
    
    Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 
    
    4
    nếu không

Các giá trị định tuyến được chỉ định bằng cách sử dụng thuộc tính

<a asp-page="/page">Click</a>
9 số ít và thuộc tính nhiều
<a asp-page="/page">Click</a>
0 là cộng

### Ambient Route Values 

Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 

Trong phần Chi tiết, bạn muốn cung cấp liên kết đến trang Chỉnh sửa, trang này cũng chấp nhận tham số dữ liệu tuyến đường có tên là

### Ambient Route Values 

Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 
7. Không cần chỉ định thuộc tính
### Ambient Route Values 

Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 
8 cho trình trợ giúp thẻ neo vì giá trị môi trường xung quanh từ ngữ cảnh yêu cầu hiện tại sẽ được sử dụng theo mặc định. Do đó, những điều sau đây là đủ để tạo liên kết đến
### Ambient Route Values 

Route Data values for the current request are considered _ambient_ values in ASP.NET Core 2.1 and earlier*. This means that they do not necessarily need to be specified when generating links from the current page to another that requires the same Route Data value. For example, you may provide a page that shows the details of an order that has an `id` as a route data parameter: `"{id:int}"`. 
9

`<a asp-page="edit">Edit</a>`

In this case, you only need to specify a value for `asp-route-*` if you want to override the ambient value. 

If you override an ambient value by explicitly providing a value, all subsequent ambient values will be ignored. The template `"{pageno=1}/{sortby=Id}"` specifies two parameters, each with a default value. If you override the `pageno` value e.g. `<a asp-page="list" asp-route-pageno="2">2</a>`, the `sortby` value is omitted from the generated URL (along with any subsequent parameters) so that the generated URL is `list/2`. However, if you override the `sortby` value, the `pageno` value is retained (along with any other previous parameters).

***Note:** This behaviour changed in ASP.NET Core 2.2. Ambient route values are no longer reused when the destination page is different to the source page.

Tùy chọn định tuyến

Trình trợ giúp thẻ neo sẽ tạo các URL có tên trang được viết hoa khi bạn chuyển một giá trị cho thuộc tính

<a asp-page="/page">Click</a>
5 e. g

<a asp-page="page">Click</a>

trở thành

<a href="/Page">Click</a>

Bạn có thể định cấu hình

`<a asp-page="edit">Edit</a>`

In this case, you only need to specify a value for `asp-route-*` if you want to override the ambient value. 

If you override an ambient value by explicitly providing a value, all subsequent ambient values will be ignored. The template `"{pageno=1}/{sortby=Id}"` specifies two parameters, each with a default value. If you override the `pageno` value e.g. `<a asp-page="list" asp-route-pageno="2">2</a>`, the `sortby` value is omitted from the generated URL (along with any subsequent parameters) so that the generated URL is `list/2`. However, if you override the `sortby` value, the `pageno` value is retained (along with any other previous parameters).

***Note:** This behaviour changed in ASP.NET Core 2.2. Ambient route values are no longer reused when the destination page is different to the source page.
1 nếu bạn muốn URL được tạo hoàn toàn là chữ thường

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.Configure<RouteOptions>(options =>
    {
        options.LowercaseUrls = true;
    });
}

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.Configure<RouteOptions>(options =>
    {
        options.LowercaseUrls = true;
    });
}

Một tùy chọn khác,

`<a asp-page="edit">Edit</a>`

In this case, you only need to specify a value for `asp-route-*` if you want to override the ambient value. 

If you override an ambient value by explicitly providing a value, all subsequent ambient values will be ignored. The template `"{pageno=1}/{sortby=Id}"` specifies two parameters, each with a default value. If you override the `pageno` value e.g. `<a asp-page="list" asp-route-pageno="2">2</a>`, the `sortby` value is omitted from the generated URL (along with any subsequent parameters) so that the generated URL is `list/2`. However, if you override the `sortby` value, the `pageno` value is retained (along with any other previous parameters).

***Note:** This behaviour changed in ASP.NET Core 2.2. Ambient route values are no longer reused when the destination page is different to the source page.
2 sẽ dẫn đến dấu gạch chéo được thêm vào tên trang trong mọi trường hợp

Làm cách nào để chuyển giá trị biến trong thẻ neo trong HTML?

href”, hãy thêm biến vào đó (Ở đây chúng tôi đã sử dụng biến có tên “XYZ”). Sau đó, chúng ta cần nối giá trị vào URL. Bây giờ URL của chúng tôi đã sẵn sàng với biến và giá trị của nó được thêm vào nó. Trong ví dụ bên dưới, chúng tôi sẽ thêm một biến có tên 'XYZ' và giá trị của nó là 55.

Làm cách nào để thêm tham số vào URL trong HTML?

Các tham số được thêm vào cuối URL sau ký hiệu '? ' và nhiều . Thông số truy vấn chủ yếu được sử dụng để chỉ định và sắp xếp nội dung trên trang web nhưng chúng cũng thường được sử dụng để theo dõi lưu lượng truy cập.

Chúng ta có thể truyền tham số trong thẻ neo như sử dụng phương thức đăng không?

Cách duy nhất để truyền dữ liệu bằng thẻ liên kết là đặt chúng vào chuỗi truy vấn .