在MVC视图之间传递值

时间:2013-05-02 19:38:45

标签: c# asp.net-mvc razor

我需要将从这些Radioboxes中选择的值传递到“List”视图

cshtml文件

@Html.RadioButtonFor(m => m.SmokeHouse, 1)
@Html.RadioButtonFor(m => m.SmokeHouse, 0)

@Html.RadioButtonFor(m => m.SmokeCar, 1)
@Html.RadioButtonFor(m => m.SmokeCar, 0)

@Html.RadioButtonFor(m => m.SmokeWork, 1)    
@Html.RadioButtonFor(m => m.SmokeWork, 0)

[HttpPost]
public ViewResult SmokingEnvironments()
{
   return View("List");
}

public class Screen
{
    public int SmokeCar { get; set; }
    public int SmokeHouse { get; set; }
    public int SmokeWork { get; set; }
}

1 个答案:

答案 0 :(得分:1)

假设您有一个发布到该操作的提交按钮,您只需要更新控制器以将模型作为参数并将其传递给下一个视图:

[HttpPost]
public ViewResult SmokingEnvironments(Screen model)
{
   return View("List", model);
}