kenyu73
kenyu73

Reputation: 681

cshtml post with asp-route parameter

Why am I getting a null for my py parameter? There's other examples in the code already that use hard links and py populates, its just in the form post that py is null. tn is OK.

Probably a simple fix, but not sure where the problem is.

<form asp-action="Edit" asp-controller="Fields" asp-route-py="9" asp-route-tn="1" method="post">

// GET: Fields/Edit/5
[Authorize]
public async Task<IActionResult> Edit(long? id, int? py, int? tn)

Upvotes: 0

Views: 175

Answers (1)

Llazar
Llazar

Reputation: 3322

I think that your project must have another edit method but this method must be Post like the form you have posted.

Usually a crud application has 2 methods one Post to post data to the server and one Get to retrieve data from the server.

Edit method with Get request

/ GET: Fields/Edit/5
[Authorize]
public async Task<IActionResult> Edit(long? id, int? py, int? tn)

Edit method with Post request

[HttpPost] 
[ValidateAntiForgeryToken] 
public async Task<IActionResult> Edit(long id, int? py, int? tn, [Bind("Id,....)

Upvotes: 1

Related Questions