想要获得国家明智的城市 [英] Want to get state wise city

查看:67
本文介绍了想要获得国家明智的城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表城市和州我希望在下拉列表中获得州智慧城市,我已经在下拉列表中输出了两个表数据但是状态明智的城市不工作,我也给了外键,我想要在mvc5做这件事,



我尝试过:



i已经用给定的外键完成了我的两个表格

将两个DDl的数据输出到

但是我无法获得状态明智的城市



i已经尝试使用jscrpit但没有工作



这里是我的控制器代码: -



i am having 2 tables city and state i want to get state wise city in dropdownlist , i have already got both tables data in output in dropdownlist but state wise city is not working , i have also given foreign key, i want to to do this thing in mvc5,

What I have tried:

i have done my both tables with given foreign key
getting both DDl's data in output
but i cant get it state wise city

i have tried it using jscrpit but not worked

here is my controler code:-

namespace Web4.Controllers
{
    public class AccountController : Controller
    {
        private void PopulateLookups(eBusPassSystemEntities db)
        {
            IEnumerable<SelectListItem> item = db.tbl_state.Select(C => new SelectListItem
            {
                Value = C.state_name,
                Text = C.state_name
            }).ToList(); 

            ViewBag.state = item;

            IEnumerable<SelectListItem> itenn = db.tbl_city.Select(C => new SelectListItem
            {
                Value = C.city_name,
                Text = C.city_name
            }).ToList();

            ViewBag.city = itenn;

        }
       


        [HttpGet]
        public ActionResult register(tbl_state t)
        {
            using (eBusPassSystemEntities db = new eBusPassSystemEntities())
            {
                PopulateLookups(db);
                
            }

            return View();

           
        }

        [HttpPost]
        public ActionResult Register(tbl_user u)
        {
            if (!ModelState.IsValid)
            {
                using (eBusPassSystemEntities db = new eBusPassSystemEntities())
                {
                    PopulateLookups(db);
                }

                return View();
            }

            using (eBusPassSystemEntities Db = new eBusPassSystemEntities())
            {
                Db.tbl_user.Add(u);
                Db.SaveChanges();
            }

            TempData["message"] = "Hello" + u.name + " Your Account Has been Succesfully created.";
            return RedirectToAction("Success");
        }

        [HttpGet]
        public ActionResult Success()
        {
            ViewBag.message = TempData["message"];
            return View();
        }
    }
}

推荐答案

以下是您的分步指南:< a href =http://www.c-sharpcorner.com/UploadFile/sourabh_mishra1/cascading-dropdownlist-in-Asp-Net-mvc/> ASP.Net MVC中的级联DropDownList [ ^ ]
Here is a step by step guide for you: Cascading DropDownList in ASP.Net MVC[^]


关于级联功能的文章。



创建使用实体框架和ADO.NET在MVC中级联DropDownList [ ^ ]

使用Razor在MVC 4中创建简单的级联DropDownList [ ^ ]

学习要点:如何在MVC3层叠DropdownList中使用国家/州/城市使用Jquery与示例 [ ^ ]

在ASP.Net MVC中使用jQuery AJAX的级联(依赖)国家/地区城市DropDownLists [ ^ ]

使用MVC的级联下拉列表, LINQ to SQL和AJAX [ ^ ]
Tons of article on Cascading functionality.

Creating Cascading DropDownList In MVC Using Entity Framework And ADO.NET[^]
Creating Simple Cascading DropDownList In MVC 4 Using Razor[^]
Learning Point: How to Use Country/State/City in MVC3 Cascading DropdownList Using Jquery with Example[^]
Cascading (Dependent) Country State City DropDownLists using jQuery AJAX in ASP.Net MVC[^]
Cascading Dropdown List With MVC, LINQ to SQL and AJAX[^]


这篇关于想要获得国家明智的城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆