prvi
This commit is contained in:
46
EveryThing/Pages/Files/Create.cshtml.cs
Normal file
46
EveryThing/Pages/Files/Create.cshtml.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
|
||||
namespace EveryThing.Pages.Files
|
||||
{
|
||||
public class CreateModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public CreateModel(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IActionResult OnGet()
|
||||
{
|
||||
ViewData["IdCompanyFk"] = new SelectList(_context.CodeTableCompanies, "IdCompany", "Ceo");
|
||||
return Page();
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public new File File { get; set; }
|
||||
|
||||
// To protect from overposting attacks, please 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.Files.Add(File);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user