I am new to ASP.NET Core 2.0 Razor Pages web app framework. The problem is the following: I need to create html form for complex [BindProperty]
class and separate it's complex fields in partial views or editors (like in MVC):
public class BasicInformation
{
// complex filed
public Name Name { get; set; }
public string Email { get; set; }
// collection of objects
public IEnumerable<Address> Addresses { get; set; }
//complex field
public PhoneNumber PhoneNumber { get; set; }
}
I would like to achieve something like this:
<h4>BasicInformation</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Resume" />
@Html.EditorFor(m => m.BasicInformation.Name)
<div class="form-group">
<label asp-for="BasicInformation.Email" class="control-label"></label>
<input asp-for="BasicInformation.Email" class="form-control" />
<span asp-validation-for="BasicInformation.Email" class="text-danger"></span>
</div>
<div class="form-group">
@Html.EditorFor(m => m.BasicInformation.PhoneNumber)
</div>
...
<div class="form-group">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</form>
</div>
</div>`
And my page model:
public class BasicInformationFormModel : PageModel
{
[BindProperty]
public BasicInformation BasicInformation { get; set; }
public IActionResult OnGet()
{
return Page();
}
public IActionResult OnPost(BasicInformation basicInformation)
{
// all data from separate views / editors need to be present in basicInformation
return Page();
}
}
How can I achieve this?