我想要一个注册表单,其中新用户输入他们的详细信息N他在数据库中注册/添加,如何在数据库MYSQL中添加/删除用户的更新信息?
编辑==注意 - >
I M逐行完成本教程 因此,数据库部分的时间是59:30 LINK == https://www.youtube.com/watch?v=VAtVv1Q7ufM
User1Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using OnlineJobRecruitmentSystemMVC.Models;
namespace OnlineJobRecruitmentSystemMVC.Controllers
{
public class User1Controller : Controller
{
public PplContext db = new PplContext();
//GET: User1
public ActionResult User11()
{
var peoplefinal = db.people1.ToList();
return View(peoplefinal);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include =
"1,'namai','passishere',1,1")] People personalDetail)
{
if (ModelState.IsValid)
{
db.people1.Add(personalDetail);
db.SaveChanges();
return RedirectToAction("User11");
}
return View(personalDetail);
}
}
}
模型
1)People.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace OnlineJobRecruitmentSystemMVC.Models
{
public class People
{
public int id { get; set; }
public String username { get; set; }
public String password { get; set; }
public int hasuploadedresume { get; set; }
public int hasbeenselected { get; set; }
}
}
2)PplContext.cs
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace OnlineJobRecruitmentSystemMVC.Models
{
public class PplContext : DbContext
{
public DbSet<People> people1 { get; set; }
}
}
第3)Ppldatabseinitializer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Web;
namespace OnlineJobRecruitmentSystemMVC.Models
{
public class Ppldatabseinitializer : DropCreateDatabaseIfModelChanges<PplContext>
{
protected override void Seed(PplContext context)
{
var ppllist = new List<People>
{
new People { id = 1, username = "vaibhav123", password = "12345", hasuploadedresume = 0, hasbeenselected = 0 },
new People { id = 2, username = "aman123", password = "12345", hasuploadedresume = 0, hasbeenselected = 0 }
};
foreach (var temp in ppllist)
{
context.people1.Add(temp);
}
context.SaveChanges();
}
}
}
4)的Web.config 我只在web.config文件中添加了这一行
<add name="PplContext" connectionString="Data Source= (LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnetdatabase.mdf;Initial Catalog=aspnet-OnlineJobRecruitmentSystemMVC-20161105011202;Integrated Security=True" providerName="System.Data.SqlClient" />