I have a view model 'ScansViewModel' that's being passed as null on a post method on controller. On the GET method it gets passed as a parameter, but if I edit it and try to post a new file, its passed as null.
my classes are as follows
EditApplicantScanViewModel.cs
public class EditApplicantScanViewModel
{
public int ApplicantId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public ScansViewModel ScansViewModel { get; set; }
}
then my view for this
@model Models.ViewModels.EditApplicantScanViewModel
<form asp-action="Edit" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-8">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="ApplicantId" />
<div class="form-group col-md-4">
<label asp-for="FirstName" class="control-label"></label>
<input asp-for="FirstName" class="form-control" />
<span asp-validation-for="FirstName" class="text-danger"></span>
</div>
<div class="form-group col-md-4">
<label asp-for="LastName" class="control-label"></label>
<input asp-for="LastName" class="form-control" />
<span asp-validation-for="LastName" class="text-danger"></span>
</div>
<div class="form-group col-md-4">
<label asp-for="EmailAddress" class="control-label"></label>
<input asp-for="EmailAddress" class="form-control" />
<span asp-validation-for="EmailAddress" class="text-danger"></span>
</div>
@Html.Partial("_Scans", Model.ScansViewModel)
<button type="submit" class="btn btn-primary">
Save
</button>
</div>
</div>
</form>
In my partial I have the parent model passing in the scan view model.
@model Models.ViewModels.ScansViewModel
<div class="form-row">
<div class="form-group col-md-4">
<input asp-for="File1" >
</div>
<div class="form-group col-md-4">
<input asp-for="File2" >
</div>
<div class="form-group col-md-4">
<input asp-for="File3" >
</div>
</div>
When I select a new file on the post method its passed as null. Do I have to combine these two models in to one for this to be achieved? as I will need to use the partial in other places too.