I have a Dto class with nested classes im using to bind a model to my view.
The nested class has an id property that needs to be passed back into my app service, but so far im getting null
Some things i've tried are
<input asp-for="StoreWalk.Department.Id" type="hidden" />
@Html.HiddenFor(h => h.StoreWalk.Department.Id)
<input type="hidden" name="version" value="@Model.StoreWalk.Version" />
<input type="hidden" name="department.id" value="@Model.StoreWalk.Department.Id" />
<input type="hidden" name="department_id" value="@Model.StoreWalk.Department.Id" />
<input type="hidden" id="StoreWalk_Department_Id" name="department_id" value="@Model.StoreWalk.Department.Id" />
My model class
public class CreateOrEditStoreWalkViewModel
{
public CreateOrEditStoreWalkDto StoreWalk { get; set; }
public bool IsEditMode => StoreWalk.Id.HasValue;
}
public class CreateOrEditStoreWalkDto : EntityDto<int?>
{
// Id property is implemented in `EntityDto` as int?
[Required]
public string Store { get; set; }
public string Comments { get; set; }
public byte[] Signature { get; set; }
public int Version { get; set; }
public DepartmentsDto Department { get; set; }
}
public class DepartmentsDto : EntityDto
{
// Id property is implemented in `EntityDto`
public string Name { get; set; }
}
EntityDto can be found here: https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Application/Services/Dto/EntityDto.cs
My View.cshtml
<form name="StoreWalkInformationsForm" role="form" novalidate class="form-validation">
@if (Model.IsEditMode)
{
<input type="hidden" name="id" value="@Model.StoreWalk.Id" />
}
// Note, im not trying all at once, these are just what ive tried so far
<input asp-for="StoreWalk.Department.Id" type="hidden" />
@Html.HiddenFor(h => h.StoreWalk.Department.Id)
<input type="hidden" name="version" value="@Model.StoreWalk.Version" />
<input type="hidden" name="department.id" value="@Model.StoreWalk.Department.Id" />
<input type="hidden" name="department_id" value="@Model.StoreWalk.Department.Id" />
<input type="hidden" id="StoreWalk_Department_Id" name="department_id" value="@Model.StoreWalk.Department.Id" />
.........
</form>
I expect the department.id to be set but department is always null.

3 days and I finally figured out a solution.
<input type="hidden" name="department[id]" value="@Model.StoreWalk.Department.Id" />
<input type="hidden" name="department[name]" value="@Model.StoreWalk.Department.Name" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With