2020-12-30

Cannot get Query elements on razor page

I have two query-selection on my page one for customers and one for suppliers. Why do I not see any elements?

== c# code ==

c# code of page

Pic of VS19 with debugger

in debugger elements are shown see pic number 2

== in Razor Page==

Pic of HTML Code

Unfortunately I cannot see any items. Any Ideas?

Layout of page

Attached you get my code sorry for only posting pictures

My c# Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc.Rendering;
using WorkCollaboration.Data;
using WorkCollaboration.Models;

namespace WorkCollaboration.Pages.Contacts
{ 
    public class CreateModel : PageModel
    {
        private readonly WorkCollaboration.Data.WorkCollaborationContext _context;

        public CreateModel(WorkCollaboration.Data.WorkCollaborationContext context)
        {
            _context = context;
        }

    public async Task<IActionResult> OnGetAsync()
        {
            CustomerDropDownDisp = await _context.CustomerDropDown.ToListAsync();  // Added for DropDown
            SupplierDropDownDisp = await _context.SupplierDropDown.ToListAsync();  // Added for DropDown
            return Page();
        }

        [BindProperty]
        public Contact Contact { get; set; }
        public DayOfWeek DayOfWeek { get; set; }
        public IEnumerable<CustomerDropDown> CustomerDropDownDisp { get; set; }
        public IEnumerable<SupplierDropDown> SupplierDropDownDisp { get; set; }

        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            _context.Contact.Add(Contact);
            await _context.SaveChangesAsync();

            return RedirectToPage("/ContactsOverview/Index");
        }
    }
}

Here my Razor Page Html

@page 
@model WorkCollaboration.Pages.Contacts.CreateModel

@{
    ViewData["Title"] = "Create";
    ViewData["RandomId"] = Guid.NewGuid().GetHashCode();
}

<h1>Create</h1>
<h4>Contact</h4>
<p>
    <a asp-page="/ContactsOverview/Index">Back to Index</a>
</p>
<hr />
<div class="row">
    <div class="col-md-4">
        <form method="post">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="Contact.ContactId" class="control-label"></label>
                <input asp-for="Contact.ContactId" value='@ViewData["RandomId"]' readonly="readonly" class="form-control" />
                <span asp-validation-for="Contact.ContactId" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.LastName" class="control-label"></label>
                <input asp-for="Contact.LastName" class="form-control" />
                <span asp-validation-for="Contact.LastName" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.FirstName" class="control-label"></label>
                <input asp-for="Contact.FirstName" class="form-control" />
                <span asp-validation-for="Contact.FirstName" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.CustomerId" class="control-label"></label>
                <input asp-for="Contact.CustomerId" class="form-control" />
                <span asp-validation-for="Contact.CustomerId" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.CustomerId" class="control-label"></label>
                <select id="CusId" aps-items="@(new SelectList(Model.CustomerDropDownDisp,"CusId","CusName"))">
                    <option value="" selected disabled> -- Select Customer--</option>>
                </select>
                <span asp-validation-for="Contact.CustomerId" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.SupplierId" class="control-label"></label>
                <input asp-for="Contact.SupplierId" class="form-control" />
                <span asp-validation-for="Contact.SupplierId" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.SupplierId" class="control-label"></label>
                <select id="SupId" aps-items="@(new SelectList(Model.SupplierDropDownDisp,"SupId","SupName"))">
                    <option value="" selected disabled> -- Select Supplier--</option>>
                </select>
                <span asp-validation-for="Contact.SupplierId" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.PrivateStreet" class="control-label"></label>
                <input asp-for="Contact.PrivateStreet" class="form-control" />
                <span asp-validation-for="Contact.PrivateStreet" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.PrivateStreetNo" class="control-label"></label>
                <input asp-for="Contact.PrivateStreetNo" class="form-control" />
                <span asp-validation-for="Contact.PrivateStreetNo" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.PrivateStreetAdditionalInfo" class="control-label"></label>
                <input asp-for="Contact.PrivateStreetAdditionalInfo" class="form-control" />
                <span asp-validation-for="Contact.PrivateStreetAdditionalInfo" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.PrivateZip" class="control-label"></label>
                <input asp-for="Contact.PrivateZip" class="form-control" />
                <span asp-validation-for="Contact.PrivateZip" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.PrivateTown" class="control-label"></label>
                <input asp-for="Contact.PrivateTown" class="form-control" />
                <span asp-validation-for="Contact.PrivateTown" class="text-danger"></span>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Contact.PrivateCountry, htmlAttributes: new { @class = "form-group" })
                <div class="form-group">
                    @Html.DropDownListFor(model => model.Contact.PrivateCountry, new List<SelectListItem>
                    {
                        new SelectListItem {Text = "CH", Value = "CH", Selected = true },
                        new SelectListItem {Text = "D", Value = "D" },
                        new SelectListItem {Text = "FL", Value = "FL" },
                    }, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Contact.PrivateCountry, "", new { @class = "text-danger" })
                </div>
            </div>
            <div class="form-group">
                <label asp-for="Contact.PrivatePhone" class="control-label"></label>
                <input asp-for="Contact.PrivatePhone" class="form-control" />
                <span asp-validation-for="Contact.PrivatePhone" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.BusinessPhone" class="control-label"></label>
                <input asp-for="Contact.BusinessPhone" class="form-control" />
                <span asp-validation-for="Contact.BusinessPhone" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.MobilePhone" class="control-label"></label>
                <input asp-for="Contact.MobilePhone" class="form-control" />
                <span asp-validation-for="Contact.MobilePhone" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Contact.Mail" class="control-label"></label>
                <input asp-for="Contact.Mail" class="form-control" />
                <span asp-validation-for="Contact.Mail" class="text-danger"></span>
            </div>
            <select asp-for="DayOfWeek" asp-items="Html.GetEnumSelectList<DayOfWeek>()">
                <option value="">Choose a day</option>
            </select>
            <div class="form-group">
                <input type="submit" value="Create" class="btn btn-primary" />
                <a href="/ContactsOverview/Index" class="btn btn-primary">Back to List</a>
            </div>
        </form>
    </div>
</div>


from Recent Questions - Stack Overflow https://ift.tt/2KMCojJ
https://ift.tt/eA8V8J

No comments:

Post a Comment