I am making asp.net core program with razor pages where I want to send data from my index.cshtml page to the indes.cshtml.cs, I am using the asp-for method in my form to pass the value to a variable in the .cs file but the value never gets passed. this is what the code looks like.
this is the form on the frond end
<form method="post" autocomplete="on">
<label class="offscreen" for="searchText">Enter a game</label>
<input type="text" id="searchText" class="searchText" name="searchText" list="games" asp-for="gameViewModel.Name"/>
</form>
This is the .ccs file behind it (it is a little bigger than this but this is the variable I am passing it to)
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
[BindProperty]
public GameViewModel gameViewModel { get; set; }
}
And this is the viewModel
public class GameViewModel
{
public string Name { get; set; }
}
I have done the same thing on other pages of my program and there the name value gets passed to the gameViewModel just fine, it is only in the index page this doesn’t work.
I have tried to alter a bunch of small things but nothing changes.
Bradreslam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.