locked
How to create asp dot net core depend dropdown RRS feed

  • Question

  • User1896377498 posted

    Hear I use in two table 

    1st are hear

    CREATE TABLE [dbo].[TouchPoint](
    	[SL] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
    	[RouteName] [nvarchar](50) NOT NULL,
    	[RouteType] [nvarchar](50) NOT NULL,
    	[TouchPoint] [nvarchar](50) NOT NULL,
    	[DistanceKM] [nvarchar](50) NULL,
    	[Status] [bit] NULL,
    	[InputUser] [nvarchar](50) NULL,
    	[InputDate] [datetime] NULL,
     CONSTRAINT [PK_TouchPoint] PRIMARY KEY CLUSTERED 
    (
    	[RouteName] ASC,
    	[RouteType] ASC,
    	[TouchPoint] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO

    2nd table

    CREATE TABLE [dbo].[RouteType](
    	[SL] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
    	[RouteTypeList] [nvarchar](50) NOT NULL,
    	[Status] [bit] NULL,
     CONSTRAINT [PK_RouteType] PRIMARY KEY CLUSTERED 
    (
    	[RouteTypeList] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO

    controller

            public ActionResult Index()
            {
                List<RouteTypeModel> RouteTypeList = _context.RouteType.ToList();
                ViewBag.RouteTypeList = new SelectList(RouteTypeList, "RouteTypeList", "RouteTypeList");
                return View();
            }
    
            public JsonResult GetStateList(string RouteTypeList)
            {
                //db.Configuration.ProxyCreationEnabled = false;
                List<TouchPointModel> StateList = _context.TouchPoints.Where(x => x.RouteType == RouteTypeList).ToList();
                return Json(StateList);
            }
    

    View

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    
    
    <br />
    <br />
    <div class="container">
        <div class="form-group">
            @if (ViewBag.CountryList != null)
            {
                @Html.DropDownListFor(model => model.RouteTypeModel.RouteTypeList, ViewBag.RouteTypeList as SelectList, "--Select Country--", new { @class = "form-control" })
            }
        </div>
        <div class="form-group">
            @Html.DropDownListFor(model => model.TouchPointModel.TouchPoint, new SelectList(" "), new { @class = "form-control" })
        </div>
    </div>
    
    <script>
        $(document).ready(function () {
            $("#RouteTypeList").change(function () {
                $.get("/Home/GetStateList", { RouteTypeList: $("#RouteTypeList").val() }, function (data) {
                    $("#TouchPoint").empty();
                    $.each(data, function (index, row) {
                        $("#TouchPoint").append("<option value='" + row.TouchPoint + "'>" + row.TouchPoint + "</option>")
                    });
                });
            })
        });
    </script>

    Please solve my problem, when i select fast dropdown not get in value in 2nd dropdown please check my code and give me solution

    Monday, March 1, 2021 12:06 PM

Answers

  • User-474980206 posted

    Your ID’s are not correct. View source to get correct values, or override the ID with know values on the drop down render.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 1, 2021 4:50 PM