Click here to Skip to main content
14,930,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to return two dropdowns in view,im able to return first dropdown list in view. can anyone help me how to return 2 dropdown in same view attached code what i tried

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication10.Models;

namespace WebApplication10.Controllers
{
    
    public class userdataController : Controller
    {
        // GET: userdata
        public ActionResult userdata()
        {
         
           userdata model = new userdata
             {
                model.environmentlist = new List<string> { "w1", "w2", "w3", "w4" };
        };
            return View(model);


        }

           
        
        [HttpPost]
        public ActionResult userdata(userdata model)
        {

            if (string.IsNullOrEmpty(model.unumber))
            {
                model.ValidationMsg = "Please enter unumber";

            }

            else
            {
                switch (model.envoption)
                {

                    case "w1":
                        switch(model.regionoption)
                        {
                            case "us1":

                                break;
                            case "us2":
                                break;

                            case "us3":
                                break;

                        }
                        break;
                      
                    case "w2":
                        switch (model.regionoption)
                        {
                            case "us1":

                                break;
                            case "us2":
                                break;

                            case "us3":
                                break;
                        }
                        break;
                    case "w3":
                        switch (model.regionoption)
                        {
                            case "us1":

                                break;
                            case "us2":
                                break;

                            case "us3":
                                break;

                        }
                        break;

                    case "w4":
                        switch (model.regionoption)
                        {
                            case "us1":
                                break;

                              
                            case "us2":
                                break;

                            case "us3":
                                break;

                        }
                        break;
                }

            }

          model.environmentlist = new List<string> { "w1", "w2", "w3", "w4" };
            model.region= new List<string> { "us1", "us2", "us3" };
            return View(model);

        }

    }

}
Posted
Updated 25-Dec-20 18:21pm

1 solution

I think you are asking how can you return a second, different list with which to create a drop down list box or similar. You just need to create another collection type of property and a property to contain the index of the selected item in that second list as part of your model, then create your second list in the view using those properties. If you are creating that as part of a form that submits to your post action, the model binder should resolve your second list on post. If you are using AJAX to post to your action, you just need to create the data element the same we you are doing for your first list.

If I have misunderstood your question, please let me know.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900