解决这个问题的最佳方法是什么?我有一个文本框,教师在其中输入学生 ID,我想根据输入的 ID 显示学生信息。显示学生信息后,我有一个下拉列表,其中填充了一个列表,其中列出了学生注册的所有课程。从该下拉列表中选择一门课程后,我想在表格上显示学生的进度表格上的特定部分。我该如何处理?这是我到目前为止所拥有的:
控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Student.Models;
namespace Student.Controllers
{
public class StudentFormController : Controller
{
//
// GET: /StudentForm/
public ActionResult Index()
{
return View("StudentForm");
}
public ActionResult DisplayStudentDetails(string StudentId)
{
StudentDataContext db = new StudentDataContext();
var StudentName = (from p in db.vwStudent.Where(a => a.StudentID == StudentId)
group p by p.StudentName into g
select g.Key).FirstOrDefault();
var StudentClassList = (from p in db.vwStudent.Where(a => a.StudentID == StudentId)
group p by p.ClassID into g
select g.Key).ToList();
ViewData["StudentName"] = StudentName;
ViewData["StudentClassList "] = StudentClassList ;
return View("StudentForm");
}
public ActionResult DisplayClassDetails(string StudentId, string ClassId)
{
StudentDataContext db = new StudentDataContext();
ViewData.Model = (from p in db.vwStudentProgress.Where(a => a.StudentID == StudentId && a.ClassID == ClassId);
return View("LPForm");
}
}
}
视图(表格):
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content3" ContentPlaceHolderID="TitleContent" runat="server">
Student Form
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
<form id="form2" method="get" action="/StudentForm/DisplayStudentDetails/" runat="server">
<div style="text-align: left; height: 202px;">
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
Student Id:<input type="text" name="id" value="<%=HttpContext.Current.Request.QueryString["StudentId"]%>" /><br />
Student Name:<input type="text" name="StudentName" value="<%=ViewData["ShortName"]%>" /><br />
Classes Enrolled in:
<select name="Classes">
<%if (ViewData["Classes"] != null)
{%>
<% foreach (int? Classes in (List<int?>)ViewData["Classes"])
{%>
<option><%=Classes%></option>
<%}%>
<%}%>
</ContentTemplate>
</asp:UpdatePanel>
<input type="submit" value="Display Student Details"/>
</div>
</form>
</asp:Content>