dotnet / dotnet/aspnetcore

Display value correctly in Razor View after Model Binding

Open
#54,995 0 comments 0 reactions 0 assignees View on GitHub
area-mvc untriaged
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

Hello,

I have 2 action methods **'IncreaseStock'** in my **'StockController'**.
![image](https://github.com/dotnet/razor/assets/22199398/92e91f48-9a26-4635-a8d5-43658cdc10e4)

I send the **'StockViewModel**' to View.
![image](https://github.com/dotnet/razor/assets/22199398/28d1778e-a96a-4c65-80c5-b35833a3551e)

The view has a post form.
![image](https://github.com/dotnet/razor/assets/22199398/6ee8b47a-2376-4d56-8329-fe325ea7ef3d)

When I post this form back to the server, I need to display **'storeItem.Quantity'** back to the view.
![image](https://github.com/dotnet/razor/assets/22199398/7d9a925e-cd56-430f-8d99-9a935833582d)

The **POST 'IncreaseStock'** currently returns an empty view.
![image](https://github.com/dotnet/razor/assets/22199398/43208839-44cd-4b62-8afd-b3e4d17a7c4b)

My run for the application, even when the **GET 'IncreaseStock'** passes a view model to the view.
![image](https://github.com/dotnet/razor/assets/22199398/6b3aeeeb-6cf8-4a48-83a9-77ba4bbfc426)

After posting the form, the **'storeItem.Quantity'** should be displayed in the same view. The user should be able to select values
for **SelectedStore'** and **'SelectedItem** again and hit the **'IncreaseStock'** button, and the **'storeItem.Quantity'** should be displayed again and so on.

Thanks.

Contributor guide

Open the contributing guide

Research direction

The issue shows GET and POST IncreaseStock actions in StockController, a StockViewModel, and a Razor view, but names no repository files or tests. Start by reviewing the POST action and view described in the issue; done means the view displays storeItem.Quantity after posting and permits repeated selections and submissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.