【问题标题】:MVC5 attribute routing not workingMVC5 属性路由不起作用
【发布时间】:2014-12-27 11:34:47
【问题描述】:

我在我的项目中使用 MVC5 路由属性。

我在主页上有搜索控件。当用户点击搜索按钮时,控制值将被传递给搜索控制器动作。

使用 MVC5 之前的路由属性 URL 是 http://localhost:5344/Search/View1?City=XYZ&Cat=ABC

家庭控制器代码:

public ActionResult IndexFront(string City, string Search, string hidCategory, string btnSubmit)
    {


        return RedirectToAction("View1", "Search", new { CityS = City, SearchS = Search, Cat = hidCategory });          


    }

搜索控制器代码:

 [Route("Search/{CatS}/{CityS}/{SearchS?}", Name="SearchWithCityCat")]
    public ActionResult View1(string CityS, string SearchS, string CatS)
    {

        var searchModel = new SearchModel();

        return View(searchModel);

    }

使用路由属性装饰 View1 并单击搜索按钮后,它显示相同的 URL 并给出错误“找不到页面”。

我没有找到解决这个问题的方法。

我做得对吗?

请帮忙。提前致谢。

【问题讨论】:

  • 试试return RedirectToAction("SearchWithCityCat", "Search",

标签: c# asp.net-mvc-4 routing asp.net-mvc-routing url-routing


【解决方案1】:

谢谢大家。

找到答案了。我从 Home 控制器传递了错误的参数名称。

【讨论】:

    猜你喜欢
    • 2016-01-06
    • 2013-11-14
    • 1970-01-01
    • 2016-01-12
    • 2017-09-29
    • 1970-01-01
    • 2013-06-01
    • 2023-04-10
    相关资源
    最近更新 更多