asp.net主页传递所有操作的数据

时间:2011-12-20 00:30:41

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-2 action-filter

母版页包含表单,其中的表单包含下拉列表,当选择任何选项时,表单将被提交。 请说优雅的方式保持每个动作方法的mvc模式我可以得到下拉选择值

2 个答案:

答案 0 :(得分:0)

我不认为这会是一个问题,因为您可以在页面上有多个表单。只需在您的母版页上添加一个表单即可。像这样的东西

Master.cshtml

@Html.BeginForm("{Action}", "{Controller}")
{
    <select id="formList" name="formList">
        // your options go here
    </select>

    <input type="submit" value="OK" />
}

@RenderBody

当{Action}和{Controller}显然是控制器时,您希望在用户从下拉列表中选择某些内容时处理该处理。然后你的观点会有自己的形式。

SomeView.cshtml(显示POST示例)

@{
    Layout = "pathTo/Master.cshtml";
}

@Html.BeginForm()
{
    // define your view
}

您的html会将两种不同的表单发布到两个不同的操作中。

答案 1 :(得分:0)

以下步骤是一种可能的解决方案。

  1. 当您更改必须在Cookie
  2. 中存储该值时,您在母版页中有下拉列表
  3. 创建价值按以下链接提供 http://www.dotnetguy.co.uk/post/2010/03/07/aspnet-mvc-working-smart-with-cookies-custom-valueprovider
  4. 在上面的链接中按照名称的每个动作使用它。
  5. 它对我有用。

相关问题