1

In my application there is two types of registration. Business type and individual type. Business type has some extra fields to be filled. I dont want to use two forms.

What I want is When the user clicks on Individual reg.. , some text boxes will be hidden and when Business type user clicks on the radio button every field should appear. I dont want to use jquery. How can we achieve this in asp.net mvc4

  • 1
    You can use simple javascript to hide/show your textboxes : http://stackoverflow.com/questions/17621515/how-to-show-and-hide-input-fields-based-on-radio-button-selection – christof13 Jul 29 '14 at 12:08

2 Answers2

1

You can do something like below without Javascript.

Assuming your controls are inside div's, and two css classes (div-visible, div-hidden) are defined accordingly.

<div class="@(Model.IsBusinessType?"div-visible":"div-hidden")">
     //Business controls
</div>

<div class="@(Model.IsBusinessType?"div-hidden":"div-visible")">
     //Individual controls
</div>
Kaf
  • 33,101
  • 7
  • 58
  • 78
0

I think there are at least three approaches you can take depending on a few factors...

1) Basic Javascript (if you're not going to do this kind of thing more than once/often in your project)

document.getElementById("yourID").style.display='none'...'block'... and so on

2) jQuery - if you need this kind of thing a little more often, plus all the other great things that jQuery can do

  • look up jquery hide() and show() functions - pretty easy to do ('#yourID').hide()...show()

3) Knockout.js - a more comprehensive way to bind data client side and can easily do what you describe, but does so much more than this too - more of a learning curve, but great tool if you need significant client-side functionality like this - probably overkill if you don't need much more than you describe.

Bob Mac
  • 259
  • 1
  • 7