I have now two Pages. One where i can create "People" (Lastname, Firstname, Email) and one where i can create "Hobbies" (Activity).
But the Goal would be to have the "create People" Page with checkboxes to choose which Hobby/Activity from our "Activity" entries. Something like this:
Now i have no Idea how to code this. All i know is that i need many-to-many relationships. And something like a middleclass from "people" and "hobby" ("peoplehobby" in my case. Code below: Models/People.cs
using System;
using System.Collections.Generic;
namespace Customer.Models
{
public class People
{
public int ID { get; set; }
public string Lastname { get; set; }
public string Firstname { get; set; }
public string Email { get; set; }
}
public class Hobby
{
public int ID { get; set; }
public string Activity { get; set; }
}
public class PeopleHobby
{
public int PeopleId { get; set; }
public People People { get; set; }
public int HobbyId { get; set; }
public Hobby Hobby { get; set; }
}
}
The dbcontext file (Data/CustomerContext)
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Customer.Models;
namespace Customer.Models
{
public class CustomerContext : DbContext
{
public CustomerContext (DbContextOptions<CustomerContext> options)
: base(options)
{
}
public DbSet<Customer.Models.People> People { get; set; }
public DbSet<Customer.Models.Hobby> Hobby { get; set; }
}
}
Does anyone know how i can implement this idea? I couldn't really find anything useful in the web (that i also understood).
Thanks in advance
domi_12
PS: I'm working with Visual Studio 17 and .net core 2.1 if this is needed
Member
1 Points
3 Posts
[Asp.Net Core MVC Webapp] How to add a checkbox from your entries
Aug 17, 2018 01:20 PM|domii_12|LINK
Hello
I'm pretty new to programming, especially to .Net Core.
Anyways i just made this Tutorial on "how to make your first .net Core Webapp MVC" ( https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/?view=aspnetcore-2.1 )
I have now two Pages. One where i can create "People" (Lastname, Firstname, Email) and one where i can create "Hobbies" (Activity).
But the Goal would be to have the "create People" Page with checkboxes to choose which Hobby/Activity from our "Activity" entries. Something like this:
Now i have no Idea how to code this. All i know is that i need many-to-many relationships. And something like a middleclass from "people" and "hobby" ("peoplehobby" in my case. Code below: Models/People.cs
The dbcontext file (Data/CustomerContext)
Does anyone know how i can implement this idea? I couldn't really find anything useful in the web (that i also understood).
Thanks in advance
domi_12
PS: I'm working with Visual Studio 17 and .net core 2.1 if this is needed