Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:14:15+00:00 2026-05-23T13:14:15+00:00

I am trying to hide and unhide the textbox using dropdownlist , so for

  • 0

I am trying to hide and unhide the textbox using dropdownlist , so for instance when 0 is selected from drop down, no textbox should appear on the view , but if 1 is selected from dropdownlist , one textbox should appear similarly for selected value 2 , it should show two box , and then I want to pass the selected value and textbox text to http[post] in controller action to carry out some calculation. I can do all this in webforms but I dont know how to acheive this in mvc 2, I can pass the value from view to controller using Form collection but how will I pass the dropdownlist value. Any examples or suggestions will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:14:15+00:00Added an answer on May 23, 2026 at 1:14 pm

    There are many ways to implement this so let’s take one example using javascript to manage the input fields based on the selected value of the dropdown list.

    As always start with a view model:

    public class MyViewModel
    {
        public string[] Values { get; set; }
        public int SelectedItem { get; set; }
        public IEnumerable<SelectListItem> Items
        {
            get
            {
                return Enumerable.Range(0, 4).Select(x => new SelectListItem
                {
                    Value = x.ToString(),
                    Text = x + " Item(s)"
                });
            }
        }
    }
    

    then a controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new MyViewModel
            {
                SelectedItem = 2,
                Values = new[] { "", "" }
            };
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            // Here you will get the model properly initialized
            return View(model);
        }
    }
    

    and finally the view:

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<AppName.Models.MyViewModel>" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Index</title>
        <script type="text/javascript" src="<%: Url.Content("~/scripts/jquery-1.5.1.js") %>"></script>
        <script type="text/javascript">
            $(function () {
                $('#SelectedItem').change(function () {
                    var count = parseInt($(this).val(), 10);
                    if (count == 0) {
                        $('#values').html('');
                        return;
                    }
    
                    for (var i = 0; i < count; i++) {
                        var item = $(':text[name="Values[' + i + ']"]');
                        if (item.length < 1) {
                            $('#values').append(
                                $('<div/>').html(
                                    $('<input/>', {
                                        type: 'text',
                                        'data-index': i,
                                        name: 'Values[' + i + ']',
                                        value: ''
                                    })
                                )
                            );
                        }
                    }
    
                    $('#values :text').each(function (index, element) {
                        if (index >= count) {
                            $(element).parent('div').remove();
                        }
                    });
    
                });
            });
        </script>
    </head>
    <body>
        <div>
            <% using (Html.BeginForm()) { %>
                <%= Html.DropDownListFor(
                    x => x.SelectedItem, 
                    new SelectList(Model.Items, "Value", "Text")
                ) %>
    
                <div id="values">
                    <% for (int i = 0; i < Model.Values.Length; i++) { %>
                        <div>
                            <%= Html.EditorFor(x => x.Values[i]) %>
                        </div>
                    <% } %>
                </div>
    
                <input type="submit" value="OK" />
            <% } %>
        </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to hide the iPad keyboard from a modal view controller but it
I'm trying to hide actual sub-directory from url path using mod_rewrite. The folder actual
im trying to hide all the selected element on document ready, but only the
I am trying to hide/unhide a submenu item (menumanager) from the context (popup menu)
I'm trying to hide an event from an inherited class, but not via EditorBrowserable
I am trying to hide the button based on the user's role using the
I'm trying to hide some of my Perl program from the end user to
I'm trying to hide the following code listed below from members that are not
I am trying to hide div with Value2. I tried many things but no
I am trying to hide an array of elements but facing problem while writing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.