根据单选按钮选择显示/隐藏部分

时间:2014-07-02 20:21:12

标签: c# asp.net-mvc

我正在开发一个ASP.NET MVC 4 Web应用程序。我有一个视图,根据选择的单选按钮列表(3个单选按钮A),B),C)显示/隐藏某些部分。 ) 没有使用jquery / javascript似乎没有办法做到这一点?

根据这篇文章:

Postback on RadioButtonFor in MVC

 "There is no server side event occurring when the user changes the selection of a radio button."

我可以使用单选按钮执行回发并根据选择显示/隐藏部分吗?

如果没有javascript和纯ASP.NET MVC 4+代码,请告诉我。

1 个答案:

答案 0 :(得分:0)

这是控制器代码:

[HttpPost]
public ActionResult SaveIndex()
{
    return View();
}

以下是视图的代码:

<div>
@using (Ajax.BeginForm("SaveIndex", "Home", new AjaxOptions { HttpMethod = "Post"}, new { id = "MainForm" }))
    {
        @Html.RadioButton("My Radio1", "Radio1", new { onchange = "this.form.submit();" })
        @Html.RadioButton("My Radio2", "Radio2", new { onchange = "this.form.submit();" })
    }
</div>