simasaurucevicius
Member
- Joined
- Aug 14, 2021
- Messages
- 18
- Programming Experience
- Beginner
Hello.I hope there isn't a SQL server connection problem,it seems that it doesn't read the file correctly and can't find the information from the server?Thank you for any help
The code where the problem is(EmployeeManagerController):
The code where the problem is(EmployeeManagerController):
C#:
using EmployeeManagerApp.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EmployeeManagerApp.Controllers
{
public class EmployeeManagerController : Controller
{
private AppDbContext db = null;
public EmployeeManagerController(AppDbContext db)
{
this.db = db;
}
private void FillCountries()
{
List<SelectListItem> countries = (from c in db.Countries
orderby c.Name ascending
select new SelectListItem() { Text = c.Name, Value = c.Name }).ToList();
ViewBag.Countries = countries;
}
[HttpGet]
public IActionResult Create()
{
FillCountries();
return View();
}
[HttpPost]
public IActionResult Create(Employee emp)
{
FillCountries();
if (ModelState.IsValid)
{
db.Employees.Add(emp);
db.SaveChanges();
}
return View(emp);
}
public IActionResult Index()
{
return View();
}
}
}
Attachments
Last edited by a moderator: