I am quite new to ASP .Net, and could use some help... I have an ASP .Net Core 1.1 MVC web app. In it, I have an "Edit" view for editing a simple object, which is bound to a model, which a corresponding controller calls when routed to it.
This is the view:
@modelInspectionsTestClient.Models.Property@{ViewData["Title"] ="Edit";}<h2>Edit</h2>@Html.ValidationSummary();<form asp-action="Edit"><div class="form-horizontal"><h4>Property</h4><hr /><div asp-validation-summary="ModelOnly" class="text-danger"></div><input type="hidden" asp-for="Id" /><div class="form-group"><label asp-for="UnitNumber" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="UnitNumber" class="form-control" /><span asp-validation-for="UnitNumber" class="text-danger"></span></div></div><div class="form-group"><label asp-for="BuildingName" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="BuildingName" class="form-control" /><span asp-validation-for="BuildingName" class="text-danger"></span></div></div><div class="form-group"><label asp-for="Street" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="Street" class="form-control" /><span asp-validation-for="Street" class="text-danger"></span></div></div></div></form><div><a asp-action="Index">Back to List</a></div>@sectionScripts{@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}}
This is the controller which calls that view:
// GET: Property/Edit/5publicActionResultEdit(int id){returnView();}
And this is the model:
namespaceInspectionsTestClient.Models{//[Table("property")]publicclassProperty{[Key][DatabaseGenerated(DatabaseGeneratedOption.Identity)]publicint?Id{get;set;}[MaxLength(10,ErrorMessage="Unit number too long")][Display(Name="Unit #")]publicstringUnitNumber{get;set;}[MaxLength(45,ErrorMessage="BuildingName name too long")]publicstringBuildingName{get;set;}[MaxLength(45,ErrorMessage="Street too long")]publicstringStreet{get;set;}}}
So when I navigate to that page, the controller gets triggered, and correctly returns the Edit view. I have also confirmed the "id" parameter is indeed populated with the id of the object I wish to edit. However, the Edit view loads in the browser, all the input textboxes are empty. I would expect them to be pre-populated with the values for the object in question. What am I missing?
Thanks...