从主页/索引问题调用部分视图

时间:2018-10-19 19:01:07

标签: asp.net-mvc asp.net-mvc-4

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

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

我现在正在创建选择部件,但出现类似这样的错误。

  

找不到路径'/'的控制器或未实现IController。

这是

这是FilterController:

 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");

2 个答案:

答案 0 :(得分:1)

您应该将剃须刀电话更改为此

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

您的控制器是 FilterController ,因此,您应使用“ 过滤器 ”作为第二个参数, FilterForm

答案 1 :(得分:1)

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

cts:element-walk