如何修复下拉列表中的传递两个参数

时间:2019-04-24 18:00:59

标签: javascript c# asp.net-mvc razor

我在View中有2个下拉列表,但我不知道如何获取脚本工作的ID,请帮助我。在此先感谢

这是我的IndexList创建列表的控制器

public ActionResult IndexList() {
  ViewBag.falcuty_id = new SelectList(db.faculties, "faculty_id",
    "faculty_name");
  ViewBag.linktoYearId = GetYears();
  return View();
}

这是我的下拉列表控制器,用于创建用于选择年份的控制器

private SelectList GetYears() {
  int CurrentYear = DateTime.Now.Year;

  for (int i = 2017; i <= CurrentYear; i++) {
    ddlYears.Add(new SelectListItem {
      Text = i.ToString(),
      Value = i.ToString()
    });
  }
  return new SelectList(ddlYears, "Value", "Text");
}

这是需要传递参数的方法。该方法将通过教职员工ID和date_post

来查询和计算内容的数量
public ActionResult List(int date,string date) {
  int count = (db.contents.Where(x => x.date_post.Value.Year == date && x.faculty_id == "IT")).Count();

  Session["count"] = count;
  return RedirectToAction("IndexList", "contents");
}

和我的索引索引。脚本不起作用

@using (Html.BeginForm())
{
    <div class="row" style="border:solid; border-width:thin; padding:20px; height:400px;">
        <div class="col-lg-12 text-center">
            <div class="row">

                @Html.DropDownList("falcuty_id", null, new   { @onChange = "selectFaculty(this)" })

                <div class="col-lg-6" align="left">
                    @Html.DropDownList("linktoYearId", null, "---Select year---",new {
                   @id = "ddlYears",
                   @onChange = "SelectedValue(this)",
                   @class = "form-control",
                   @style = "width:200px"
               })
                    <h1>@Session["count"]</h1>
                </div>

            </div>

        </div>
    </div>
}

<script>
   function SelectedValue(ddlObject) {
      var selectedValue = ddlObject.value;
    }
   function selectFaculty(falObject1) {
     var selectedValue = falObject1.value;
     window.location.href = '@Url.Action("List","contents")?date=' + parseInt(selectedValue.ddlObject.value) + '?faculty=' + falObject1.value;
   }
</script>

0 个答案:

没有答案