62,046
社区成员
发帖
与我相关
我的任务
分享
namespace MvcApplication7.Models
{
public class Mymodel
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(20)]
public string Name { get; set; }
[Required]
[MaxLength(30)]
public string StandardName { get; set; }
[Required]
[MaxLength(4)]
public int Sigma_b { get; set; }
}
}
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication7.Models;
namespace MvcApplication7.Controllers
{
public class Default1Controller : Controller
{
private MvcApplication7Context db = new MvcApplication7Context();
public ActionResult Index()
{
return View(db.Mymodels.ToList());
}
public ActionResult Details(int id = 0)
{
Mymodel mymodel = db.Mymodels.Find(id);
if (mymodel == null)
{
return HttpNotFound();
}
return View(mymodel);
}
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Mymodel mymodel)
{
if (ModelState.IsValid)
{
db.Mymodels.Add(mymodel);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(mymodel);
}
}
}
public class MvcApplication7Context : DbContext
{
public MvcApplication7Context() : base("name=MvcApplication7Context")
{
}
public DbSet<Mymodel> Mymodels { get; set; }
}