Home > Software design >  Parameter Passing in HTML
Parameter Passing in HTML

Time:12-03

I have 2 levels of EF Core scaffolds:

  1. for shipment headers and
  2. for shipment detail lines.

From the header's ./Index page, there's a link that passes the shipment header's ID so that only that shipment's lines are displayed on its ./Index page. However, I can't get the shipment header's ID to pass in the link for the line's ./Create page, so the result is a constraint error when the line is saved.

When I attempt to use {id:int} in the asp-route-id for the create URL, it either only sends a translation of that text or reverts back to the URL for the ./Index.

@page  "{id:int}"

<a asp-page="./Create/" asp-route-id="{id:int}">Create New</a>

Does anyone know how to pass the ID as a parameter to another HTML page?

CodePudding user response:

Im not quite sure what kind of technologie you use.

I would possibly specify the page name like @page "/something/{id:int}". Could be that the / is missing.

However if you are using .razor files you need this in the @code part like:

[Parameter]
public int Id { get; set;}

In case it is a .cshtml file and using mvc you can see here or here how to pass parameters in a differnt way

CodePudding user response:

Try to use @RouteData.Values["xxx"] to get data from Route.

<a asp-page="./Create/" asp-route-id=@RouteData.Values["id"]>Create New</a>
  • Related