Hi @Nathi Mabinza ,
<input class="form-radio-input" name="status" value="True" type="radio" asp-for="Job.PublicSubmissionReviewed" /> Approve <input class="form-check-input" name="status" value="False" type="radio" asp-for="Job.PublicSubmissionReviewed" /> Reject
The issue relates the name
attribute, since you add the name
attribute, in the Post method, you could a parameter named status
, then use it to get the selected value. Code like this:
public async Task<IActionResult> Review(int id, JobViewModel model, bool status)
If you want to get the radio button selected value via the JobViewModel, you should remove the name
attribute.
Refer the following sample:
Model:
public class JobViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public Boolean PublicSubmissionReviewed { get; set; }
}
View page:
@model WebApplication6.Models.JobViewModel
<div class="row">
<div class="col-md-4">
<form asp-action="Review">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group form-check-inline">
<label class="form-check-label">
<input class="form-radio-input" value="True" type="radio" asp-for="PublicSubmissionReviewed" /> Approve
</label>
</div>
<div class="form-group form-check-inline">
<label class="form-check-label">
<input class="form-check-input" value="False" type="radio" asp-for="PublicSubmissionReviewed" /> Reject
</label>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
</div>
</div>
Controller:
public IActionResult Review()
{
JobViewModel model = new JobViewModel()
{
Id = 101,
Name = "Job A"
};
return View(model);
}
[HttpPost]
public IActionResult Review(int id, JobViewModel model)
{
return View();
}
The result as below:
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion