从 Home/Index 问题调用局部视图

Calling Partial View from Home/Index problem

我正在创建一个网页,显示 3 种不同类型的关注者(红色、蓝色、黄色)和一个用户可以用来过滤的过滤器表单。

例如,如果客户 select 从下拉列表中选择红色选项,我只想向他们显示红色关注者。

我现在正在创建 select 部分,但我收到一个错误,内容如下。

The controller for path '/' was not found or does not implement IController.

这是

这是过滤器控制器:

 public class HomeController : Controller
{
    private asp6Entities db = new asp6Entities();
    public ActionResult Index()
    {
        var allFlowers = db.FLOWERs.ToList();
        List<FLOWER> result = new List<FLOWER>();
        foreach (var flower in allFlowers)
        {
            FLOWER model = new FLOWER();
            model = flower;
            result.Add(model);
        }
        return View(result);
    }

    public ActionResult About()
    {
        ViewBag.Message = "Our History";

        return View();
    }

    public ActionResult Contact()
    {
        ViewBag.Message = "Main Store and Distribution Center.";

        return View();
    }

    [HttpPost]
    public ActionResult Index(FilterModel fromColorFilter)
    {
        string SelectedColor = (fromColorFilter.ColorSelected);

        var allFlowers = db.FLOWERs.ToList();
        List<FLOWER> result = new List<FLOWER>();

        foreach (var flower in allFlowers)
        {
            if (flower.COLOR.COLOR_NAME == SelectedColor)
            {
                FLOWER model = new FLOWER();
                model = flower;
                result.Add(model);
            }
        }

        return View(result);
    }  
}

这是过滤器控制器:

 public class FilterController : Controller
{
    // GET: FilterModel
 private asp6Entities db = new asp6Entities();
    public ActionResult Index()
    {
        FilterModel model = new FilterModel();

        var color = db.COLORs.ToList().Select(s => new SelectListItem
        {
            Text = s.COLOR_NAME,
            Value = s.COLOR_ID.ToString()
        });

        return PartialView("~/Views/Shared/_FilterForm.cshtml", new FilterModel { AllColorOptions = color});
    }
}

这是 FilterMethod :

   public class FilterModel
{
    //declaring the colors selection
    public string ColorSelected { get; set; }

    //Creating the Size selection
    public string SizeSelected { get; set; }

    //Creating the starting price selection
    public int StartingPriceSelection { get; set; }

    //Creating Ends price Selection
    public int EndingPriceSelection { get; set; }


    //creating IEnumerable of all color options
    public IEnumerable<SelectListItem> AllColorOptions { get; set; }

    //creating IEnumerable of all Size Options
    public IEnumerable<SelectListItem> AllSizeOptions { get; set; }

    //creating IEnumerable of Starting Price Options
    public IEnumerable<SelectListItem> AllStartingPriceOptions { get; set; }

    //creating IEnumerable of Ending Price Options
    public IEnumerable<SelectListItem> AllEndingPriceOptions { get; set; }
}

这是主页索引:

在此主页索引中

@Html.Action("Index","FilterForm");

您应该将剃刀调用更改为此

@Html.Action("Index","Filter");

您的控制器是FilterController,因此,您应该使用“Filter”作为第二个参数,not "FilterForm"

是的,这是最好的解决方案

@Html.Action("Index","Filter");