I am trying to repopulate my input fields after the form has been submitted (with HttpPost). Is there a simple way to do this? I have a dropdown and a text box that get populated with data from the database. They each have their own functions in the controller that handle the flow of data. My goal is to have the last created data appear in the input fields after submit.
My Model
public int ID { get; set; }
public string bookName { get; set; }
public string Author { get; set; }
My View
<form method="post" asp-controller="Home" asp-action="Home" role="post">
<div class="form-group">
<label asp-for="bookName"></label>
<select name="bookName" asp-items="@(new SelectList(ViewBag.message, "ID", "bookName"))">
</select>
</div>
<div class="form-group">
<label asp-for="Author"></label>
<input asp-for="Author" class="form-control" />
</div>
<div class="form-group">
<input type="submit" value="Submit" class="btn btn-primary" />
</div>
</form>
My Controller
public void GetBooksDDL()
{
List<BookModel> bookName = new List<BookModel>();
bookName = (from b in _context.BookModel select b).ToList();
bookName.Insert(0, new BookModel { ID = 0, bookName = "" });
ViewBag.message = bookName;
}
[HttpPost("[action]")]
[Route("/Home")]
[Produces("application/json")]
public async Task<IActionResult> Home()
{
if (textbox != "")
{
//do all the submit actions
//after all of the actions are complete return the view:
GetBooksDDL();
return View();
}else
{
return Error;
}
}
I understand that I could pass in the model in the View(), but the values are always null. I tried to pass in my (BookModel model) as an argument in the HttpPost, but I get a 415 status.

