我的项目中有一个控制器
public ActionResult Create(int PeriodID = 0)
{
var ParentQry = from d in db.Periods
join sc in db.MultiRaterSurveyPeriods on d.PeriodID equals sc.PeriodID
where d.StartDate < DateTime.Now && d.EndDate > DateTime.Now && sc.StartDate < DateTime.Now && sc.EndDate > DateTime.Now
orderby d.PeriodID
select new {PeriodID = sc.MultiRaterSurveyPeriodID, PeriodName = d.PeriodName };
var GroupResp = from d in db.MultiRaterSurveyGroups
join sc in db.RelationBetweenMRSPeriodMRSGroups on d.MultiRaterSurveyGroupID equals sc.MultiRaterSurveyGroupID
where d.StartDate < DateTime.Now && d.EndDate > DateTime.Now && sc.StartDate < DateTime.Now && sc.EndDate > DateTime.Now
orderby d.MultiRaterSurveyGroupID
select new { MultiRaterSurveyGroupID = d.MultiRaterSurveyGroupID, MultiRaterSurveyGroupName = d.MultiRaterSurveyGroupName, MultiRaterSurveyPeriodID = sc.MultiRaterSurveyPeriodID };
ViewBag.PeriodID = new SelectList(ParentQry, "PeriodID", "PeriodName");
ViewBag.surveygroups = new SelectList(GroupResp, "MultiRaterSurveyGroupID", "MultiRaterSurveyGroupName");}
如何从控制器获取变量以查看ViewBag.surveyperiod的create.cshtml?
@foreach (var p in ViewBag.surveygroups)
{
<input type="hidden" class="hiddenSurveyGroups" name="hiddenSurveyGroups" id="surveygroups" value="@ViewBag.surveygroups">
}
因为我希望获得javascript的价值。
答案 0 :(得分:1)
您可以对ViewBag.surveygroups使用p.Text和p.Value。通过这个你可以访问它。
在您的情况下,您可以将value="@ViewBag.surveygroups"
替换为value="@p.Value"