【问题标题】:HttpException: A public action method 'ListCheckListType' was not found on controllerHttpException:在控制器上找不到公共操作方法“ListCheckListType”
【发布时间】:2019-07-10 08:41:57
【问题描述】:

我检查了所有解决方案,但仍然不起作用。我在布局页面中有一个部分视图页面,当我只运行部分页面时它可以工作,但是当我用布局运行另一个页面时它不起作用。

希望你能帮到我

这是我的模型:

    public CheckListType CheckListType { get; set; }
    public IEnumerable<SelectListItem> CheckListTypeList1 { get; set; }

还有我的控制器:

    public ActionResult ListCheckListType()
    {
        ControlListTypeModel listTypeModel = new ControlListTypeModel();
        List<SelectListItem> CheckListTypeList = new List<SelectListItem();
        foreach (CheckListType item in checklisttypeRepository.List().ProcessResult)
        {
            CheckListTypeList.Add(new SelectListItem { Value = item.CheckListTypeId.ToString(), Text = item.CheckListType1 });
        }
        listTypeModel.CheckListTypeList1 = CheckListTypeList;
        return PartialView("~/Areas/User/Views/CheckList/ListCheckListType.cshtml", listTypeModel);
    }

查看:

    @using TodoListApp.Areas.User.Models.ViewModel
    @model ControlListTypeModel
 <form action="/CheckList/ListCheckListType" method="get">
 <div>
    CheckListType :
 </div>

 <div>
    @Html.DropDownListFor(modelitem=>modelitem.CheckListType.CheckListTypeId,Model.CheckListTypeList1)
    <button type="button" class="butt button bg-info" style="height:40px; width:98px;">Choose CheckListType</button>
</div>

布局:

  <div class="container body-content">
    @Html.Action("ListCheckListType");

    @RenderBody(){
    }

    <hr />
    <footer>
        <p> @DateTime.Now.Year </p>
    </footer>
</div>

HttpException:在控制器上找不到公共操作方法“ListCheckListType”

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-partialview httpexception


    【解决方案1】:

    出现问题是因为它在部分视图中呈现时在错误的控制器中搜索 ListCheckListType 操作。指定控制器名称也应该修复异常

    @Html.Action("ListCheckListType", "Home"); //if action is in HomeController
    

    【讨论】:

      猜你喜欢
      • 2013-06-01
      • 2013-05-15
      • 2021-02-28
      • 1970-01-01
      • 2012-05-31
      • 2013-08-31
      相关资源
      最近更新 更多