人口国家,州,城市在mvc 5 [英] POPULATE COUNTRY,STATE,CITY in mvc 5

查看:125
本文介绍了人口国家,州,城市在mvc 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这里我想填充国家和自动加载状态并加载城市。请帮助我,然后即时通讯使用mvc 5存储库模式 .Where在存储库或控制器中编写该代码。因为我是新的mvc。

hi to all,
Here i want to populate Country and Automatically Load State and load city .Kindly help me for this then im using mvc 5 Repository pattern.Where to write that code in repository or controller. Because im new for mvc.

推荐答案

预计你知道要编写的代码,我正在编写流程以及在Repository模式中遵循的步骤。

首先,始终尝试添加上下文代码,即服务或存储库中的数据库操作,无论您拥有哪个。不应将上下文操作添加到Controller中。



存储库模式是MVC应用程序中必须的,因为它提供了松散耦合,这对于维护非常有用。因此,为此您需要使用依赖注入



现在对于你提到的查询,首先需要进行ajax调用以获取国家/地区列表,即调用存储库GetCountryList的Action方法(),假设会在那里。这将返回一个国家/地区列表。



然后在下拉列表和onSelect事件中填充这些值以获取下拉列表,添加一个函数,该函数将进行两次ajax调用以获取列表状态,类似地选择状态在下拉菜单的选择事件上遵循相同的功能。



如果有任何疑问,请跟进。

谢谢。 :)
Anticipating that you know the code to be written, I am writing you the flow and steps to follow in Repository pattern.
First, Always try to add the context code i.e. the database operations in the Service or Repository whichever you have. Context operations should not be added to the Controller.

Repository Pattern is a must in MVC application as it provides loose coupling, that is great for maintainance. So, for this you need to use Dependency Injection

Now for the query you have mentioned, you first need to make an ajax call to get the list of countries, i.e. the Action method that would call the Repository where the GetCountryList(), suppose would be there. This returns a list of Countries.

Then populate these values in a dropdown and onSelect event for the dropdown, add a function that would make two ajax call for getting the list of State, similarly on select of the State follow the same function on select event for the dropdown.

Please follow up, if any queries post back.
Thanks. :)


这可能会帮助你



级联下拉列表,包含MVC,LINQ to SQL和AJAX [ ^ ]



编辑:



http://www.dotnet-tricks.com/Tutorial/mvc/HL53191212-Custom-Validation-for-Cascading-Dropdownlist- in-MVC-Razor.html [ ^ ]
This May help you

Cascading Dropdown List With MVC, LINQ to SQL and AJAX[^]



http://www.dotnet-tricks.com/Tutorial/mvc/HL53191212-Custom-Validation-for-Cascading-Dropdownlist-in-MVC-Razor.html[^]


这篇关于人口国家,州,城市在mvc 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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