Model binder in Razor View
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
I have a Model here
```
[Serializable]
public class StaffInfoModel
{
[Display(Name = "Work Number")]
public string workNum { get; set; }
}
```
Then In my Index view, I have a input tag to bind `workNum` property
```
@model StaffInfoModel
@{
ViewData["Title"] = "Home Page";
}
@{
var data = Model;
}
```
Here is my controller code:
```
public IActionResult Index()
{
return View();
}
public IActionResult Query()
{
return View();
}
[HttpPost]
public IActionResult Query(QueryInfoModel model)
{
StaffInfoModel staff = new StaffInfoModel();
staff.workNum = "1010101010";
Console.WriteLine(staff.workNum);
return View("Index", staff);
}
public IActionResult Privacy()
{
StaffInfoModel staff = new StaffInfoModel();
staff.workNum = "1010101010";
return View("Index", staff);
}
```
And here is my query page:
```
@model QueryInfoModel
@{
ViewData["Title"] = "Query Page";
}
```
The problem is when i access privacy, It will return index view with data, And the data can be show successfully. Then when I access query page and click button, the code will access query post action then return index view with data, But the data will not show in index page. Only i add `value="@Model.workNum"` manually in input tag can show the data normally, I don't know why the same code cause different situation.
Contributor guide
Assessment
This issue has not been assessed yet.