Skip to content

Commit 83c798d

Browse files
committed
OnPostAsync
1 parent cbae84b commit 83c798d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

AspNetRunBasic/Pages/Product/Create.cshtml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using AspNetRunBasic.Repositories;
66
using Microsoft.AspNetCore.Mvc;
77
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
using Microsoft.AspNetCore.Mvc.Rendering;
89

910
namespace AspNetRunBasic.Pages.Product
1011
{
@@ -23,5 +24,19 @@ public async Task<IActionResult> OnGetAsync()
2324
ViewData["CategoryId"] = new SelectList(categories, "Id", "CategoryName");
2425
return Page();
2526
}
27+
28+
[BindProperty]
29+
public Entities.Product Product { get; set; }
30+
31+
public async Task<IActionResult> OnPostAsync()
32+
{
33+
if (!ModelState.IsValid)
34+
{
35+
return Page();
36+
}
37+
38+
Product = await _productRepository.AddAsync(Product);
39+
return RedirectToPage("./Index");
40+
}
2641
}
2742
}

0 commit comments

Comments
 (0)