Index: NutriMatch/Controllers/RecipesController.cs
===================================================================
--- NutriMatch/Controllers/RecipesController.cs	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Controllers/RecipesController.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -8,4 +8,5 @@
 using NutriMatch.Data;
 using NutriMatch.Models;
+using System.Text.Json;
 namespace NutriMatch.Controllers
 {
@@ -27,5 +28,5 @@
                 return NotFound();
             }
-            var recipe = await _context.Recipes
+            var recipe = await _context.Recipes.Include(r => r.RecipeIngredients).ThenInclude(ri => ri.Ingredient)
                 .FirstOrDefaultAsync(m => m.Id == id);
             if (recipe == null)
@@ -41,5 +42,5 @@
         [HttpPost]
         [ValidateAntiForgeryToken]
-        public async Task<IActionResult> Create([Bind("Id,Title,Instructions,Rating")] Recipe recipe)
+        public async Task<IActionResult> Create([Bind("Id,Title,Instructions")] Recipe recipe)
         {
             if (ModelState.IsValid)
@@ -47,8 +48,28 @@
                 _context.Add(recipe);
                 await _context.SaveChangesAsync();
+                string selectedIngredients = Request.Form["Ingredients"];
+                List<SelectedIngredient> ingredients = JsonSerializer.Deserialize<List<SelectedIngredient>>(selectedIngredients);
+                foreach(var i in ingredients)
+                { 
+                    _context.RecipeIngredients.Add(new RecipeIngredient {
+                        RecipeId = recipe.Id,
+                        IngredientId = i.Id,
+                        Unit = i.Unit,
+                        Quantity = i.Quantity 
+                    });
+                }
+                await _context.SaveChangesAsync();
                 return RedirectToAction(nameof(Index));
             }
             else
             {
+                foreach (var key in ModelState.Keys)
+{
+    var errors = ModelState[key].Errors;
+    foreach (var error in errors)
+    {
+        Console.WriteLine($"Key: {key} - Error: {error.ErrorMessage}");
+    }
+}
                 Console.WriteLine("Model state is invalid. Please check the input data.");
             }
@@ -70,5 +91,5 @@
         [HttpPost]
         [ValidateAntiForgeryToken]
-        public async Task<IActionResult> Edit(int id, [Bind("Id,Title,Instructions,Rating")] Recipe recipe)
+        public async Task<IActionResult> Edit(int id, [Bind("Id,Title,Instructions")] Recipe recipe)
         {
             if (id != recipe.Id)
Index: NutriMatch/Data/AppDbContext.cs
===================================================================
--- NutriMatch/Data/AppDbContext.cs	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Data/AppDbContext.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -7,5 +7,5 @@
         public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
         public DbSet<Recipe> Recipes { get; set; }
-        public DbSet<RecipeIngredients> RecipeIngredients { get; set; }
+        public DbSet<RecipeIngredient> RecipeIngredients { get; set; }
         public DbSet<Ingredient> Ingredients { get; set; }
         protected override void OnModelCreating(ModelBuilder modelBuilder)
Index: NutriMatch/Migrations/20250616162832_ChangeRecipeIngredient.Designer.cs
===================================================================
--- NutriMatch/Migrations/20250616162832_ChangeRecipeIngredient.Designer.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
+++ NutriMatch/Migrations/20250616162832_ChangeRecipeIngredient.Designer.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -0,0 +1,106 @@
+﻿// <auto-generated />
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using NutriMatch.Data;
+#nullable disable
+namespace NutriMatch.Migrations
+{
+    [DbContext(typeof(AppDbContext))]
+    [Migration("20250616162832_ChangeRecipeIngredient")]
+    partial class ChangeRecipeIngredient
+    {
+        protected override void BuildTargetModel(ModelBuilder modelBuilder)
+        {
+#pragma warning disable 612, 618
+            modelBuilder
+                .HasAnnotation("ProductVersion", "9.0.5")
+                .HasAnnotation("Relational:MaxIdentifierLength", 63);
+            NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+            modelBuilder.Entity("NutriMatch.Models.Ingredient", b =>
+                {
+                    b.Property<int>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("integer")
+                        .HasColumnName("id");
+                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+                    b.Property<float>("Calories")
+                        .HasColumnType("real")
+                        .HasColumnName("energy_kcal");
+                    b.Property<float>("Carbs")
+                        .HasColumnType("real")
+                        .HasColumnName("carbohydrates_g");
+                    b.Property<float>("Fat")
+                        .HasColumnType("real")
+                        .HasColumnName("total_fat_g");
+                    b.Property<string>("Name")
+                        .IsRequired()
+                        .HasColumnType("text")
+                        .HasColumnName("food_name");
+                    b.Property<float>("Protein")
+                        .HasColumnType("real")
+                        .HasColumnName("protein_g");
+                    b.HasKey("Id");
+                    b.ToTable("food_macronutrients", (string)null);
+                });
+            modelBuilder.Entity("NutriMatch.Models.Recipe", b =>
+                {
+                    b.Property<int>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("integer");
+                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+                    b.Property<string>("Instructions")
+                        .IsRequired()
+                        .HasColumnType("text");
+                    b.Property<float>("Rating")
+                        .HasColumnType("real");
+                    b.Property<string>("Title")
+                        .IsRequired()
+                        .HasColumnType("text");
+                    b.HasKey("Id");
+                    b.ToTable("Recipes");
+                });
+            modelBuilder.Entity("NutriMatch.Models.RecipeIngredients", b =>
+                {
+                    b.Property<int>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("integer");
+                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+                    b.Property<int>("IngredientId")
+                        .HasColumnType("integer");
+                    b.Property<float>("Quantity")
+                        .HasColumnType("real");
+                    b.Property<int>("RecipeId")
+                        .HasColumnType("integer");
+                    b.Property<string>("Unit")
+                        .IsRequired()
+                        .HasColumnType("text");
+                    b.HasKey("Id");
+                    b.HasIndex("IngredientId");
+                    b.HasIndex("RecipeId");
+                    b.ToTable("RecipeIngredients");
+                });
+            modelBuilder.Entity("NutriMatch.Models.RecipeIngredients", b =>
+                {
+                    b.HasOne("NutriMatch.Models.Ingredient", "Ingredient")
+                        .WithMany()
+                        .HasForeignKey("IngredientId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
+                    b.HasOne("NutriMatch.Models.Recipe", null)
+                        .WithMany("RecipeIngredients")
+                        .HasForeignKey("RecipeId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
+                    b.Navigation("Ingredient");
+                });
+            modelBuilder.Entity("NutriMatch.Models.Recipe", b =>
+                {
+                    b.Navigation("RecipeIngredients");
+                });
+#pragma warning restore 612, 618
+        }
+    }
+}
Index: NutriMatch/Migrations/20250616162832_ChangeRecipeIngredient.cs
===================================================================
--- NutriMatch/Migrations/20250616162832_ChangeRecipeIngredient.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
+++ NutriMatch/Migrations/20250616162832_ChangeRecipeIngredient.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -0,0 +1,75 @@
+﻿using Microsoft.EntityFrameworkCore.Migrations;
+#nullable disable
+namespace NutriMatch.Migrations
+{
+    public partial class ChangeRecipeIngredient : Migration
+    {
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropForeignKey(
+                name: "FK_RecipeIngredients_Recipes_RecipeId",
+                table: "RecipeIngredients");
+            migrationBuilder.AlterColumn<int>(
+                name: "RecipeId",
+                table: "RecipeIngredients",
+                type: "integer",
+                nullable: false,
+                defaultValue: 0,
+                oldClrType: typeof(int),
+                oldType: "integer",
+                oldNullable: true);
+            migrationBuilder.AddColumn<int>(
+                name: "IngredientId",
+                table: "RecipeIngredients",
+                type: "integer",
+                nullable: false,
+                defaultValue: 0);
+            migrationBuilder.CreateIndex(
+                name: "IX_RecipeIngredients_IngredientId",
+                table: "RecipeIngredients",
+                column: "IngredientId");
+            migrationBuilder.AddForeignKey(
+                name: "FK_RecipeIngredients_Recipes_RecipeId",
+                table: "RecipeIngredients",
+                column: "RecipeId",
+                principalTable: "Recipes",
+                principalColumn: "Id",
+                onDelete: ReferentialAction.Cascade);
+            migrationBuilder.AddForeignKey(
+                name: "FK_RecipeIngredients_food_macronutrients_IngredientId",
+                table: "RecipeIngredients",
+                column: "IngredientId",
+                principalTable: "food_macronutrients",
+                principalColumn: "id",
+                onDelete: ReferentialAction.Cascade);
+        }
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropForeignKey(
+                name: "FK_RecipeIngredients_Recipes_RecipeId",
+                table: "RecipeIngredients");
+            migrationBuilder.DropForeignKey(
+                name: "FK_RecipeIngredients_food_macronutrients_IngredientId",
+                table: "RecipeIngredients");
+            migrationBuilder.DropIndex(
+                name: "IX_RecipeIngredients_IngredientId",
+                table: "RecipeIngredients");
+            migrationBuilder.DropColumn(
+                name: "IngredientId",
+                table: "RecipeIngredients");
+            migrationBuilder.AlterColumn<int>(
+                name: "RecipeId",
+                table: "RecipeIngredients",
+                type: "integer",
+                nullable: true,
+                oldClrType: typeof(int),
+                oldType: "integer");
+            migrationBuilder.AddForeignKey(
+                name: "FK_RecipeIngredients_Recipes_RecipeId",
+                table: "RecipeIngredients",
+                column: "RecipeId",
+                principalTable: "Recipes",
+                principalColumn: "Id");
+        }
+    }
+}
Index: NutriMatch/Migrations/AppDbContextModelSnapshot.cs
===================================================================
--- NutriMatch/Migrations/AppDbContextModelSnapshot.cs	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Migrations/AppDbContextModelSnapshot.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -67,7 +67,9 @@
                         .HasColumnType("integer");
                     NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+                    b.Property<int>("IngredientId")
+                        .HasColumnType("integer");
                     b.Property<float>("Quantity")
                         .HasColumnType("real");
-                    b.Property<int?>("RecipeId")
+                    b.Property<int>("RecipeId")
                         .HasColumnType("integer");
                     b.Property<string>("Unit")
@@ -75,4 +77,5 @@
                         .HasColumnType("text");
                     b.HasKey("Id");
+                    b.HasIndex("IngredientId");
                     b.HasIndex("RecipeId");
                     b.ToTable("RecipeIngredients");
@@ -80,7 +83,15 @@
             modelBuilder.Entity("NutriMatch.Models.RecipeIngredients", b =>
                 {
+                    b.HasOne("NutriMatch.Models.Ingredient", "Ingredient")
+                        .WithMany()
+                        .HasForeignKey("IngredientId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
                     b.HasOne("NutriMatch.Models.Recipe", null)
                         .WithMany("RecipeIngredients")
-                        .HasForeignKey("RecipeId");
+                        .HasForeignKey("RecipeId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
+                    b.Navigation("Ingredient");
                 });
             modelBuilder.Entity("NutriMatch.Models.Recipe", b =>
Index: NutriMatch/Models/Recipe.cs
===================================================================
--- NutriMatch/Models/Recipe.cs	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Models/Recipe.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -14,7 +14,8 @@
         public String Title { get; set; }
         public String Instructions { get; set; }
+        [ValidateNever]
         public float Rating { get; set; }
         [ValidateNever]
-        public virtual List<RecipeIngredients> RecipeIngredients { get; set; }   
+        public virtual List<RecipeIngredient> RecipeIngredients { get; set; }   
         
     }
Index: NutriMatch/Models/RecipeIngredients.cs
===================================================================
--- NutriMatch/Models/RecipeIngredients.cs	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Models/RecipeIngredients.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -9,8 +9,13 @@
 namespace NutriMatch.Models
 {
-    public class RecipeIngredients
+    public class RecipeIngredient
     {
         [Key]
         public int Id { get; set; }
+
+        public int RecipeId { get; set; }
+        public int IngredientId { get; set; }
+
+        public virtual Ingredient Ingredient {get;set;}
 
         public String Unit { get; set; }
Index: NutriMatch/Models/SelectedIngredient.cs
===================================================================
--- NutriMatch/Models/SelectedIngredient.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
+++ NutriMatch/Models/SelectedIngredient.cs	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace NutriMatch.Models
+{
+    public class SelectedIngredient
+    {
+        public int Id { get; set; }
+        public String Name { get; set; }
+        
+        public String Unit {get;set;}
+        public float Quantity {get;set;}
+    }
+}
Index: NutriMatch/Views/Recipes/Create.cshtml
===================================================================
--- NutriMatch/Views/Recipes/Create.cshtml	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Views/Recipes/Create.cshtml	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -48,5 +48,5 @@
                 </div>
                 <input type="hidden" id="selectedIngredients" name="Ingredients" />
-             </div>
+            </div>
             <div class="form-group">
                 <input type="submit" value="Create" class="btn btn-primary" />
Index: NutriMatch/Views/Recipes/Details.cshtml
===================================================================
--- NutriMatch/Views/Recipes/Details.cshtml	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Views/Recipes/Details.cshtml	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -36,4 +36,15 @@
             @Html.DisplayFor(model => model.Rating)
         </dd>
+        <dt>
+            <ul>
+            @foreach (var ingredient in Model.RecipeIngredients){
+                <li>
+                    @Html.DisplayFor(modelItem => ingredient.Ingredient.Name) 
+                    @Html.DisplayFor(modelItem => ingredient.Quantity) 
+                    @Html.DisplayFor(modelItem => ingredient.Unit)
+                </li>
+            }
+            </ul>
+        </dt>
     </dl>
 </div>
Index: NutriMatch/Views/Shared/_Layout.cshtml
===================================================================
--- NutriMatch/Views/Shared/_Layout.cshtml	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/Views/Shared/_Layout.cshtml	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -23,5 +23,5 @@
             </div>
             <div class="container-fluid">
-               <a asp-controller="RecipesController" asp-action="Index">Create a Recipe</a>
+               <a asp-controller="Recipes" asp-action="Index">Create a Recipe</a>
             </div>
         </nav>
Index: NutriMatch/wwwroot/js/recipe-search.js
===================================================================
--- NutriMatch/wwwroot/js/recipe-search.js	(revision 867577b51ddb532b3d78531bc962de86019d1d97)
+++ NutriMatch/wwwroot/js/recipe-search.js	(revision 55a6d6698e060a0d4f1242a6790162878d7f3a29)
@@ -151,5 +151,5 @@
         return;
     }
-    const existingIngredient = selectedIngredients.find(item => item.id === ingredient.id);
+    const existingIngredient = selectedIngredients.find(item => item.Id === ingredient.id);
     if (existingIngredient) {
         alert('This ingredient is already added to the recipe.');
@@ -157,8 +157,8 @@
     }
     const newIngredient = {
-        id: ingredient.id,
-        name: ingredient.name,
-        quantity: quantity,
-        unit: unit
+        Id: ingredient.id,
+        Name: ingredient.name,
+        Quantity: quantity,
+        Unit: unit
     };
     selectedIngredients.push(newIngredient);
@@ -173,5 +173,5 @@
 }
 function removeIngredient(ingredientName) {
-    selectedIngredients = selectedIngredients.filter(item => item.name !== ingredientName);
+    selectedIngredients = selectedIngredients.filter(item => item.Name !== ingredientName);
     updateIngredientsDisplay();
     updateIngredientsInput();
@@ -184,6 +184,6 @@
         ingredientsList.innerHTML = selectedIngredients.map(ingredient => 
             `<span class="ingredient-tag" style="display: inline-block; background-color: #e3f2fd; padding: 5px 10px; margin: 2px; border-radius: 15px; font-size: 14px;">
-                ${escapeHtml(ingredient.quantity)} ${escapeHtml(ingredient.unit)} of ${escapeHtml(ingredient.name)}
-                <span class="remove" onclick="removeIngredient('${escapeHtml(ingredient.name)}')" 
+                ${escapeHtml(ingredient.Quantity)} ${escapeHtml(ingredient.Unit)} of ${escapeHtml(ingredient.Name)}
+                <span class="remove" onclick="removeIngredient('${escapeHtml(ingredient.Name)}')" 
                       style="cursor: pointer; margin-left: 8px; color: #dc3545; font-weight: bold;" 
                       title="Remove ingredient">&times;</span>
@@ -195,4 +195,5 @@
     if (hiddenInput) {
         hiddenInput.value = JSON.stringify(selectedIngredients);
+        console.log('Updated hidden input:', hiddenInput.value);
     }
 }
@@ -217,12 +218,2 @@
     return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
 }
-window.RecipeSearch = {
-    addIngredient: addIngredient,
-    removeIngredient: removeIngredient,
-    getSelectedIngredients: () => [...selectedIngredients],
-    clearIngredients: () => {
-        selectedIngredients = [];
-        updateIngredientsDisplay();
-        updateIngredientsInput();
-    }
-};
