我想问你我的项目时间表 我目前正在学习这种技术 所以请帮帮我
此图片用于选择一组:
我想在此表中为每个添加到数据库的字段然后显示在标签中:
这是我的控制器
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web.Mvc;
using TimeTable2.Models;
using System.Collections.Generic;
using System;
namespace TimeTable2.Controllers
{
public class TablesController : Controller
{
private table_systemEntities1 db = new table_systemEntities1();
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult TheTables()
{
PopulateDepartmentsDropDownList();
PopulateClassroomsDropDownList();
PopulateCoursesDropDownList();
PopulateTeachersDropDownList();
PopulateFacultiesDropDownList();
PopulateLevelsDropDownList();
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult TheTables([Bind(Include = "TabelsID,TeacherID,CourseID,LevelID,DepartmentID,ClassRoomID,TimesID,DaysID,Years,Semester,Measure")] Tabels tabels)
{
try
{
if (ModelState.IsValid)
{
db.Tabels.Add(tabels);
db.SaveChanges();
}
}
catch (DataException /* dex */)
{
ModelState.AddModelError("", "Unable to save changes. Try again .");
}
ViewBag.ClassRoomID = new SelectList(db.Class_Room, "ClassRoomID", "Name", tabels.ClassRoomID);
ViewBag.DaysID = new SelectList(db.Days, "DayID", "Name", tabels.DaysID);
ViewBag.LevelID = new SelectList(db.Level, "LevelID", "Name", tabels.LevelID);
ViewBag.TeacherID = new SelectList(db.Teacher, "TeacherID", "Name", tabels.TeacherID);
ViewBag.TimesID = new SelectList(db.Times, "TimesID", "Name", tabels.DaysID);
ViewBag.CourseID = new SelectList(db.Course, "CourseID", "Name", tabels.CourseID);
ViewBag.FacultyID = new SelectList(db.Faculty, "FacultyID", "Name", tabels.FacultyID);
ViewBag.DepartmentID = new SelectList(db.Department, "DepartmentID", "Name", tabels.DepartmentID);
ViewBag.LevelID = new SelectList(db.Level, "LevelID", "Name", tabels.LevelID);
return Json(tabels, JsonRequestBehavior.AllowGet);
}
public ActionResult DetailsofTable()
{
PopulateDepartmentsDropDownList();
PopulateClassroomsDropDownList();
PopulateCoursesDropDownList();
PopulateTeachersDropDownList();
PopulateFacultiesDropDownList();
PopulateLevelsDropDownList();
return View();
}
public ActionResult CreateTheTable()
{
PopulateDepartmentsDropDownList();
PopulateClassroomsDropDownList();
PopulateCoursesDropDownList();
PopulateTeachersDropDownList();
PopulateFacultiesDropDownList();
PopulateLevelsDropDownList();
return View();
}
public JsonResult GetDepartmentById(int ID)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.Department.Where(p => p.FacultyID == ID), JsonRequestBehavior.AllowGet);
}
public JsonResult GetTeacherById(int ID)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.Teacher_Course.Where(p => p.CourseID == ID), JsonRequestBehavior.AllowGet);
}
public JsonResult GetFacultyById(int ID)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.Class_Room.Where(p => p.ClassRoomID == ID), JsonRequestBehavior.AllowGet);
}
public JsonResult GetCoursesById(int ID)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.Teacher_Course.Where(p => p.DepartmentID == ID), JsonRequestBehavior.AllowGet);
}
private void PopulateDepartmentsDropDownList(object selectedDepartment = null)
{
var departmentsQuery = from d in db.Department
orderby d.Name
select d;
ViewBag.DepartmentID = new SelectList(departmentsQuery, "DepartmentID", "Name", selectedDepartment);
}
private void PopulateClassroomsDropDownList(object selectedClassRooms = null)
{
var classroomsQuery = from d in db.Class_Room
orderby d.Name
select d;
ViewBag.ClassRoomID = new SelectList(classroomsQuery, "ClassRoomID", "Name", selectedClassRooms);
}
private void PopulateCoursesDropDownList(object selectedCourses = null)
{
var coursesQuery = from d in db.Course
orderby d.Name
select d;
ViewBag.CourseID = new SelectList(coursesQuery, "CourseID", "Name", selectedCourses);
}
private void PopulateTeachersDropDownList(object selectedTeachers = null)
{
var teacherQuery = from d in db.Teacher
orderby d.Name
select d;
ViewBag.TeacherID = new SelectList(teacherQuery, "TeacherID", "Name", selectedTeachers);
}
private void PopulateFacultiesDropDownList(object selectedFaculties = null)
{
var facultyQuery = from d in db.Faculty
orderby d.Name
select d;
ViewBag.FacultyID = new SelectList(facultyQuery, "FacultyID", "Name", selectedFaculties);
}
private void PopulateLevelsDropDownList(object selectedLevels = null)
{
var levelQuery = from d in db.Level
orderby d.Name
select d;
ViewBag.LevelID = new SelectList(levelQuery, "LevelID", "Name", selectedLevels);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
那么如何在同一时间在数据库中保存多个字段
抱歉,我不会说英语
答案 0 :(得分:0)