我设法成功实现插入功能,如下所示。但这是通过使用另一个视图-“创建”完成的。一旦提交,它将进入“ ViewSecurityForm”视图。但是现在,我想在“ ViewSecurityForm”中使用模式来实现插入功能。我在“ ViewSecurityForm”视图中要实现的模态很少。你能帮我怎么做吗?
我在“创建”视图中创建函数的方法:
public ActionResult Create(ServerInfo alldata)
{
try
{
db.ServerInfos.Add(alldata);
db.SaveChanges();
return RedirectToRoute(new { controller = "Employee", action = "ViewSecurityForm" });
}
catch
{
return View();
}
}
我在“ ViewSecurityForm”视图中的模态方法:
public ActionResult ViewSecurityForm()
{
/*What should I write here*/
}
我的课程:
public class ViewSecurityForm
{
public List<ServerInfo> allServerInfo { get; set; }
public List<NetworkDeviceInfo> allNetworkDeviceInfo { get; set; }
}
public class SecurityContext : DbContext
{
//Create database without name
public SecurityContext ()
{
Database.SetInitializer(new SecurityDBInitializer());
}
//Create Table as below
public DbSet<ServerInfo> ServerInfos { get; set; }
public DbSet<NetworkDeviceInfo> NetworkDeviceInfos { get; set; }
}