IndexModel is my home page and I get some data from _statusService
that I render at the partial _MyPartial
The problem that I have, is that in that partial I have a select list and I want to get different values based on the
item that is selected from form with id sel-options
.
I am new to Razor Pages, but here is my code.
@page
@model IndexModel
@{
ViewData["Title"] = "Home";
}
<section class="hero-style-2">
<div class="slider">
....
</div>
</section>
<partial name="_MyPartial" model="@Model.StatusReport" />
Partial
@using Models.Entities;
@model StatusReport
@if (Model != null)
{
<div class="row">
<div class="col-md">
<label class="label-text" for="sel-options">Status</label>
</div>
<div class="col-md-2">
<select id="sel-options" class="form-control lable-text">
<option selected value="Do">Done</option>
<option value="Done">Done</option>
<option value="Canceled">Canceled</option>
</select>
</div>
</div>
<div>
... other things to be done with StatusReport ...
</div>
}
IndexModel.cs
namespace Demo.Pages;
public class IndexModel : PageModel
{
[BindProperty]
public StatusReport StatusReport { get; set; } = new();
[BindProperty]
public string status { get; set; } = "Do";
private readonly IStatusService _statusService;
public IndexModel(IStatusService statusService)
{
_statusService = statusService;
}
public async Task<IActionResult> OnGet()
{
StatusReport = await _statusService.GetItemsWithSatus(status);
return Page();
}
}