加载单选按钮点击不同的部分美景 [英] Load Different partial views on radio button click

查看:160
本文介绍了加载单选按钮点击不同的部分美景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过这取决于单选按钮选择要加载在一个单独的div不同的部分景色。当用户点击各个按钮的局部视图应该出现,如果点击的业务,那么业务局部视图应该出现

I am trying to load different partial views in a single div by depending on radio button selection. when the user clicks on Individual button that partial view should appear, if click on Business then Business Partial view should appear

我的视图页面code是

My view page code is

<script type="text/javascript">
    $(function () {
        $("[name=RegesterHere]").on('change', function () {
            var $radio = $(this);

            $.ajax({
                url: '@Url.Action("GetRegisterForm", "Home")',
                data: RegesterHere = $radio.val(),
                type: 'GET',
                success: function (data) {
                    $("#loadpartial").html(data);
                }
            });
        });
    });
</script>

<h2>GetRegisterForm</h2>
<table>

    <tr>
        <td colspan="1">@Html.LabelFor(m => m.RegesterHere)</td>
        <td colspan="2">@Html.RadioButtonFor(m => m.RegesterHere, "Individual") Individual
                          @Html.RadioButtonFor(m => m.RegesterHere, "Business") Business</td>
    </tr>
</table>

<div id="loadpartial">
</div>

和我的控制器code是

and my controller code is

[HttpGet]
        public ActionResult GetRegisterForm(string RegesterHere)
        {
            if (RegesterHere == "Individual")
            {
                return PartialView("IndividualPartialViewName");
            }
            else
            {
                return PartialView("BusinessPartialViewName");
            }

        }

当我运行这个code,第二部分观点是直接出现。请帮我有史以来点击了哪个单选按钮,然后在相应的局部视图应加载

When I am running this code, second partial view is directly appearing. Please help me that what ever radio button is clicked then the corresponding partial view should be loaded

推荐答案

看样子,你可能不会得到这实际上是检查的单选按钮值。你可能想尝试这让检查单选按钮值:

It appears that you may not be getting the radio button value that's actually checked. You may want to try this to get the checked radio button value:

var value = $("input[name='RegesterHere']:checked").val();

,然后在Ajax调用使用:

and then use this in the ajax call:

data: RegesterHere = value,

这篇关于加载单选按钮点击不同的部分美景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆