Home > Software engineering >  EF core. When creating an MVC controller with views using EF. Creates the Create (insert) view witho
EF core. When creating an MVC controller with views using EF. Creates the Create (insert) view witho

Time:04-26

I'm trying to create an MVC controller with a view, using Scaffold. The model was created from DataBase First. The "Delete", "Edit", and "Details" views are created correctly. If I click on a record (edit) the view shows all the data. But when clicking Create New, the view doesn't show any fields, just the Create button.

View: Create

View: Edit

CodePudding user response:

Scaffolding not always work correctly. You can add fields yourself.

Code with added fields :: Create.cshtml

@model Library.Model.Models.Paise

@{
    ViewData["Title"] = "Create";
}

<h1>Create</h1>

<h4>Paise</h4>
<hr />
<div >
    <div >
        <form asp-action="Create">
            <div asp-validation-summary="ModelOnly" ></div>
            <div >
                <label asp-for="Nombre" ></label>
                <input asp-for="Nombre"  />
                <span asp-validation-for="Nombre" ></span>
            </div>
            <div >
                <label asp-for="Estado" ></label>
                <input asp-for="Estado"  />
                <span asp-validation-for="Estado" ></span>
            </div>
            <div >
                <label asp-for="Observacion" ></label>
                <input asp-for="Observacion"  />
                <span asp-validation-for="Observacion" ></span>
            </div>
            <div >
                <input type="submit" value="Create"  />
            </div>
        </form>
    </div>
</div>

<div>
    <a asp-action="Index">Back to List</a>
</div>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
  • Related