I'm developing asp.net core mvc web application. In my controller, there're two actions named 'Index' and 'Index2'.
When I submit form to 'Index2', it will return View("Index", model)
. But the view doesn't render correctly.
For example, if I input 'Steven' in the TextBox and submit to 'Index2' action, the Name property should be 'Name999'. The Textbox on the HTML should be show 'Name999', but actually, it still show 'Steven'.
The code sample:
@model WebApplication2.Controllers.Test
<form method="post" action="/home/Index2">
<div class="form-group">
<input type="text" asp-for="Name"/>
</div>
<div class="form-group">
<button type="submit">Add</button>
</div>
</form>
public IActionResult Index(Test test)
{
return View(test);
}
[HttpPost]
public IActionResult Index2(Test test)
{
test.Name = "Name999";
return View("Index",test);
}
public class Test
{
public string Name { get; set; }
}