Hi
I an ASP.net Core page called Create.cshtml with the code below. I also have a class further on that refers to a table called ListItems and another one that refers to a table called DataEntryEntry. I take it that the line @foreach (var item in Model.ListControls)
refers to the table ListItems but how does the system know this
Also in the following line
if (item.Visible == true && item.Column == "Policy Number")
This refers to the Table DataEntryControl but how does it know that the system refers to this table. Is it simply because these classes are in the folder "Model" as shown in the image? Also finally, I take it that the page Create.cshtml in the folder Pages/Policies is a name that will automatically be given for CRUD. I am really just trying to work out how things liknk up.
Thanks
@page
@model WebApplication1.Pages.Policies.CreateModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
ViewData["Title"] = "Create";
Layout = "~/Pages/Shared/_Layout.cshtml";
}
<div class="content">
<div class="row">
<div class="col-6">
<div class="page-title-box" style="margin:20px">
<a asp-page="Index" class="btn btn-danger btn-rounded">Back List</a>
</div>
</div>
<div class="col-6">
<div class="page-title-box" style="margin:20px">
<form method="post">
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<p>@Model.errorMessage</p>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<form method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-12">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label asp-for="Policy.Status" class="control-label"></label>
<select asp-for="Policy.Status" asp-items="Model.Status" class="form-control" onchange="this.form.submit()" id="Status">
</select>
<span asp-validation-for="Policy.Status" class="text-danger"></span>
</div>
@foreach (var item in Model.ListControls) //The C# code marked with @ is executed on the server before the page is sent to the client
{
if (item.Visible == true && item.Column == "Policy Number")
{
<div class="form-group col-md-6">
<label asp-for="Policy.PolicyNumber" class="control-label"></label>
@if (item.Enabled == true && item.Mandatory == true)
{
<input asp-for="Policy.PolicyNumber" required class="form-control" id="PolicyNumber" />
}
else if (item.Enabled == true && item.Mandatory == false)
{
<input asp-for="Policy.PolicyNumber" class="form-control" id="PolicyNumber" />
}
else if (item.Enabled == false && item.Mandatory == true)
{
<input asp-for="Policy.PolicyNumber" disabled required class="form-control" id="PolicyNumber" />
}
else
{
<input asp-for="Policy.PolicyNumber" disabled class="form-control" id="PolicyNumber" />
}
<span asp-validation-for="Policy.PolicyNumber" class="text-danger"></span>
</div>
}
namespace WebApplication1.Model
{
public class Item
{
public int ID { get; set; }
public string ListName { get; set; }
public string ListItem { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication1.Model
{
public class DataEntryControl
{
public int ID { get; set; }
public string Status { get; set; }
public string Table { get; set; }
public string Column { get; set; }
public bool Visible { get; set; }
public bool Enabled { get; set; }
public bool Mandatory { get; set; }
public string ValidationMessage { get; set; }
}
}
If you put the mouse over Model, a tooltip should appear telling you what the class is. Likewise, if you put it over ListControls, you should see the definition of the ListControls property, in the CreateModel class.
If you click on ListControls and press F12, you should be sent to the property's definition.