This is my first time working with web development and have decided to use ASP.NET Core MVC.
When I create a new item for the model from the View, I want to also be able to create the model that is being used by the main model.
My example:
Model Contract contains an object of type List<Variable>. When I create the Contract from the view I want to be able to create variables from the same view for the given contract.
This is the code being generated from core scaffold
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<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">
<label asp-for="Content" class="control-label"></label>
<textarea oninput="auto_grow(this)" , style="width:90%; min-height: 500px; resize: vertical; overflow: auto" asp-for="Content" class="form-control">
</textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Descrption" class="control-label"></label>
<input asp-for="Descrption" class="form-control" />
<span asp-validation-for="Descrption" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
As you can see other parameters of the Contract model are being shown except the List[Variable] and I am not sure how the best way to add it is.
public class Contract
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Content { get; set; }
public List<Variable> Variable { get; set; }
public string Descrption { get; set; }
}
I'm sorry if there are missing details. Feel free to ask questions I will be happy to provide
