public ActionResult Create([Bind(Include = "Id,date,foodName,calorie,PlansId")] Schedule schedule) { if (ModelState.IsValid) { db.Schedules.Add(schedule); db.SaveChanges(); return(RedirectToAction("Index", new { typeid = schedule.PlansId })); } ViewBag.PlansId = new SelectList(db.Plans, "Id", "planType", schedule.PlansId); return(View(schedule)); }
public ActionResult Create(FormCollection form) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Documentation", "Home")); } Plans plans = new Plans(); plans.userId = User.Identity.GetUserId(); plans.planType = Convert.ToString(form["planType"]); if (ModelState.IsValid) { db.Plans.Add(plans); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(plans)); }