为什么我不能在我的控制器中调用模型

问题描述

我有一个问题,我不知道该怎么办。我尝试了几种方法,但对我没有任何作用。我有模特儿

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace BergClinic.Models
{
    public  class Patient
    {
        [Key]
        public int Id { get; set; }

        [required]
        [display(Name ="First Name")]
        [MaxLength(50)]
        public string FirstName { get; set; }

        [required]
        [display(Name = "Last Name")]
        [MaxLength(50)]
        public string LastName { get; set; }

        [required]
        [display(Name = "Date of Birth")]
        public DateTime DateOfBirth { get; set; }

        [display(Name = "Address")]
        [MaxLength(50)]
        public string Address { get; set; }

        [display(Name = "Phone Number")]
        public string PhoneNumber { get; set; }

        [display(Name = "Gender")]
        public PatientGender Gender { get; set; }
    }

    public enum PatientGender
    {
        [display(Name ="Male")]
        Male,[display(Name = "Female")]
        Female,UnkNown
    }
}

以及包含以下逻辑的 IPatientRepositoryPatientRepository

using BergClinic.DataAccess.Data;
using BergClinic.DataAccess.Repository.IRepository;
using BergClinic.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BergClinic.DataAccess.Repository
{
    public class PatientRepository : Repository<Patient>,IPatientRepository
    {
        private readonly ApplicationDbContext _db;

        public PatientRepository(ApplicationDbContext db) : base(db)
        {
            _db = db;
        }

        public void Update(Patient patient)
        {
            var objDb = _db.Patients.FirstOrDefault(s => s.Id == patient.Id);
            if (objDb != null)
            {

                objDb.FirstName = patient.FirstName;
                objDb.LastName = patient.LastName;
                objDb.DateOfBirth = patient.DateOfBirth;
                objDb.Address = patient.Address;
                objDb.PhoneNumber = patient.PhoneNumber;
                objDb.Gender = patient.Gender;

                _db.SaveChanges();
            }
        }
    }
}

这里是包含更新方法IPatientRepository

using BergClinic.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace BergClinic.DataAccess.Repository.IRepository
{
    public interface IPatientRepository : IRepository<Patient>
    {
        void Update(Patient patient);
    }
}

一旦我在 PatientController 的管理区域中创建了它,我想初始化对象 Patient 但我不能。我想为 UpsertUpdate 创建 Insert Patient 方法,但是无论我输入什么它都看不到我的模型,只有它看到的是患者工作区

'Patient' is a namespace but is used like a type    


   using BergClinic.DataAccess.Repository.IRepository;
using Microsoft.AspNetCore.Mvc;
using BergClinic.Models;

namespace BergClinic.Areas.Admin.Controllers
{
    [Area("Admin")]
    public class PatientController : Controller
    {
        private readonly IUnitOfWork _unitOfWork;

        public PatientController(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Upsert(int? Id)
        {      
             Patient patient = new Areas.Patient
            return View();
        }


        #region API_CALLS
        [HttpGet]
        public IActionResult GetAll()
        {
            var patient = _unitOfWork.Patient.GetAll();
            return Json(new { data = patient });
        }

        #endregion
    }
}

只是注意到我使用 RepositoryPatten 和你的方式架构。我尝试重新启动 Visual Studio,但似乎什么也没发生,我尝试删除项目引用并再次尝试添加,但注意到再次发生。 这是我的 ProjectStructures 的几个场景,您可以查看:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...