Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 5 我无法在asp.net mvc中为该方法创建视图?_Asp.net Mvc 5 - Fatal编程技术网

Asp.net mvc 5 我无法在asp.net mvc中为该方法创建视图?

Asp.net mvc 5 我无法在asp.net mvc中为该方法创建视图?,asp.net-mvc-5,Asp.net Mvc 5,这里已经在dbo.aspnetusers和dbo.birthcertificate之间形成了主键和外部关系,但是当我创建dbo.birthcertificate模型时,我得到一个错误: 这是我写的代码 public class BirthCertificate { [Key] public string Id { get; set; } [Display(Name = "Birth Date")] [Required(ErrorMessag

这里已经在
dbo.aspnetusers
dbo.birthcertificate
之间形成了主键和外部关系,但是当我创建
dbo.birthcertificate
模型时,我得到一个错误:

这是我写的代码

public class BirthCertificate
{
    [Key]
    public string Id { get; set; }

    [Display(Name = "Birth Date")]
    [Required(ErrorMessage = "Birth Date is required.")]
    //[RegularExpression(@"(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$", ErrorMessage = "Invalid date format.")]
    public DateTime DOB { get; set; }

    [Display(Name = "Gender")]
    [Required(ErrorMessage = "Gender is required")]
    public char Gender { get; set; }

    [Display(Name = "Child Full Name")]
    [Required(ErrorMessage = "Child Name is required")]
    public string ChildFullName { get; set; }

    [Display(Name = "Father Name")]
    [Required(ErrorMessage = "Father is required")]
    public string FatherName { get; set; }

    [Display(Name = "Mother Name")]
    [Required(ErrorMessage = "Mother is required")]
    public string MotherName { get; set; }

    [Display(Name = "Address")]
    [Required(ErrorMessage = "Address Required")]
    public string Address { get; set; }

    [Display(Name = "PIN CODE")]
    [RegularExpression("^[1-9][0-9]{5}$", ErrorMessage = "Pincode is wrong")]
    public int PinCode { get; set; }

    [Display(Name = "Hospital Name")]
    [Required(ErrorMessage = "Hospital Name is required")]

    public string HospitalName { get; set; }

    [Display(Name = "Hospital Address")]
    public string HospitalAddress { get; set; }

    [Display(Name = "Registration Number")]
    public int RegistrationNumber { get; set; }
}


public class RegistrationsDbContext : DbContext
{
    public DbSet<BirthCertificate> BirthCertificates { get; set; }

}

public class ApplicationUser : IdentityUser
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }

    public virtual ICollection<BirthCertificate> BirthCertificates { get; set; }
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public DbSet<BirthCertificate> BirthCertificates { get; set; }

    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

public class FormsController : Controller
{
    public RegistrationsDbContext db = new RegistrationsDbContext();

    // GET: Forms
    public ActionResult Index()
    {
        return View();
    }

    [HttpGet]
    public ActionResult Register()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Register(BirthCertificate birth)
    {
        if (ModelState.IsValid)
        {
            db.BirthCertificates.Add(birth);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        else
        {
            ModelState.AddModelError("!", "Some Error Occured");
        }

        return View(birth);
    }
}
公共类出生证
{
[关键]
公共字符串Id{get;set;}
[显示(Name=“出生日期”)]
[必需(ErrorMessage=“需要出生日期”。)]
//[RegularExpression(@)(((0-1)[0-9]| 2[0-9]| 3[0-1])\/(0[1-9]| 1[0-2])\/((19-20)\d\d))$,ErrorMessage=“无效日期格式”。)
公共日期时间DOB{get;set;}
[显示(Name=“Gender”)]
[必需(ErrorMessage=“需要性别”)]
公共字符{get;set;}
[显示(Name=“子全名”)]
[必需(ErrorMessage=“需要子名称”)]
公共字符串ChildFullName{get;set;}
[显示(Name=“父名”)]
[必需(ErrorMessage=“父亲是必需的”)]
公共字符串父名称{get;set;}
[显示(Name=“母亲姓名”)]
[必需(ErrorMessage=“需要母亲”)]
公共字符串名称{get;set;}
[显示(Name=“Address”)]
[必需(ErrorMessage=“Address Required”)]
公共字符串地址{get;set;}
[显示(Name=“PIN码”)]
[RegularExpression(“^[1-9][0-9]{5}$”,ErrorMessage=“Pincode错误”)]
公共int PinCode{get;set;}
[显示(Name=“医院名称”)]
[必需(ErrorMessage=“需要医院名称”)]
公共字符串HospitalName{get;set;}
[显示(Name=“医院地址”)]
公共字符串HospitalAddress{get;set;}
[显示(名称=“注册号”)]
公共整数注册号{get;set;}
}
公共类注册DbContext:DbContext
{
公共数据库集出生证书{get;set;}
}
公共类应用程序用户:IdentityUser
{
公共异步任务GenerateUserIdentityAsync(用户管理器)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
返回用户身份;
}
公共虚拟ICollection出生证书{get;set;}
}
公共类ApplicationDbContext:IdentityDbContext
{
公共数据库集出生证书{get;set;}
公共应用程序上下文()
:base(“DefaultConnection”,throwifvv1schema:false)
{
}
公共静态应用程序上下文创建()
{
返回新的ApplicationDbContext();
}
}
公共类窗体控制器:控制器
{
public RegistrationsDbContext db=新的RegistrationsDbContext();
//获取:表格
公共行动结果索引()
{
返回视图();
}
[HttpGet]
公众行动结果登记册()
{
返回视图();
}
[HttpPost]
公共行动结果登记册(出生证明)
{
if(ModelState.IsValid)
{
db.出生证明。添加(出生);
db.SaveChanges();
返回操作(“索引”);
}
其他的
{
AddModelError(“!”,“发生了一些错误”);
}
返回视图(出生);
}
}