简体   繁体   English

在单选按钮选择更改上更改图形-ASP.NET MVC

[英]Changing graph on radio button selection change - ASP.NET MVC

I use Microsoft chart and I have below line of code to get chart. 我使用Microsoft图表,并且在下面的代码行中获取图表。

 <img src="@Url.Action("GetChart")" alt="Bar Chart using MVC" class="img-responsive" />

I have a radio button list and upon changing the selection, i need to show a different chart in the same place. 我有一个单选按钮列表,更改选择后,我需要在同一位置显示其他图表。

<form method="post" id="frmFormType">
        @Html.Label("Select Chart Type")
        @Html.RadioButton("rbChartType", "1", isChecked: true) @Html.Label("First Option")
        @Html.RadioButton("rbChartType", "2", isChecked: false) @Html.Label("Second option")
    </form>

I'm not sure if I can use jQuery change function on this "rbChartType" or use something take advantage of Form. 我不确定是否可以在此“ rbChartType”上使用jQuery更改功能或使用一些利用Form的功能。 I don't really need to re-post the page but only to change graph. 我真的不需要重新发布页面,而只需更改图表。 I am not sure how to refetch new chart when selection changed using jQuery. 当使用jQuery更改选择时,我不确定如何重新获取新图表。 Can anyone please throw some light on this? 谁能给我一点启示吗? Thanks 谢谢

Have both the images: 都有两个图像:

Make them this way: 用这种方法制作它们:

 $(function () { $("input").click(function () { $(".graph").addClass("hidden"); $("#" + $(this).attr("value")).removeClass("hidden"); }); }); 
 img {display: block;} .hidden {display: none;} 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <label><input type="radio" name="graph" value="graph-1" /> Graph 1</label> <label><input type="radio" name="graph" value="graph-2" /> Graph 2</label> <img src="https://placeholdit.imgix.net/~text?txtsize=50&txt=Graph%201&w=200&h=200" class="graph hidden" id="graph-1" /> <img src="https://placeholdit.imgix.net/~text?txtsize=50&txt=Graph%202&w=200&h=200" class="graph hidden" id="graph-2" /> 

you can try it! 你可以试试!

$(function(){
   $(":radio").click(function() { 
       //do something 
    }); 
})

if above soluation did not work,please use the debug of browser to look for the correct documents. 如果以上解决方法无效,请使用浏览器的调试功能查找正确的文档。 in this way ,you can operate documents with jquery. 这样,您可以使用jquery操作文档。


First,you have to get the srcs of each RadioButton ,if you want to change the img of src by click radio. 首先,如果要通过单击单选按钮更改src的img,则必须获取每个RadioButton的src。 $(function(){ $("input:radio").click(function(){ if($(this).is("#1")){$(".img").css('background',src1);}else{$(".img").css('background',src2);}}) $(function(){$(“ input:radio”)。click(function(){if($(this).is(“#1”)){$(“。img”)。css('background' ,src1);}其他{$(“。img”)。css('background',src2);}})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM