【问题标题】:Get ControollerContext.RouteValues from POST action从 POST 操作中获取 ControllerContext.RouteValues
【发布时间】:2015-03-09 12:57:03
【问题描述】:

我创建了局部视图,我这样称呼它:

  @{Html.RenderAction("_SearchPartial", "Search", new { RenderVillaOption=true,RenderHotelOption=true,Frame=true,RenderAccommodationOption=true,RenderRentACarOption=true});}

我传递了一些值,因为我希望在声明 od 部分视图附近看到它们,并且我可以得到这些值,这很好。 比我在 SearchController 中发布一些操作。我想得到这个“选项”(我在局部视图声明中指定的路由值。如何实现呢? 这是动作方法:

 public string SearchAndRedirect([FromBody] SearchAPIModel searchModel)
    {
        var redirectUrl = "";

        var c = ControllerContext;
        switch (searchModel.ProductType)

【问题讨论】:

  • 请发布您的搜索控制器方法,您曾使用该方法调用局部视图

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


【解决方案1】:

在 ActionMethod 中将它们作为参数获取:

    public ActionResult Search(bool RenderVillaOption, bool RenderHotelOption, bool Framem ...  )
    {
    }

【讨论】:

  • 还有其他方法吗,我已经收到了一些对象,这些对象的值取决于用户与搜索框的交互。我不想混合这些对象,即用户 bahavoiur 和搜索框选项,这完全是别的东西。
  • 我认为您可以使用您的 Option 属性制作一个 ViewModel 并将其传递给您的部分,您可以在其中设置值并将它们作为 OptionsViewModel 发布到您的操作,但我需要查看您的操作.
【解决方案2】:

作为@vortex 答案的替代方案,考虑到您的评论,您可以使用Request.Params

public ActionResult Search(...)
{
     var renderVillaOption = Request.Params["RenderVillaOption"];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多