本文介绍了当在MVC中选择国家/地区时,jquery将在下拉列表中绑定状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jquery在注册用户时从MVC 4中的另一个下拉列表中选择国家时绑定下拉状态..



我在一个列表中有州名称 stateList通过功能GetStatesList从下拉列表中选择国家名称



[HttpPost]

[AllowAnonymous]

public ActionResult GetStatesList(int countryid)

{

TracFindDALContainer tracFindStates = null;

List< registermodel> stateList = null;

尝试

{

使用(tracFindStates = new TracFindDALContainer())

{

var statebind =(来自tracFindStates.States中的s

在s.Id上的tracFindStates.Countries中加入c等于c.Id

其中s.CountryID == countryid

选择新的RegisterModel

{

Stateid = s.Id,

StateName = s.StateName });



if(statebind == null)

返回Json(null);

stateList = (List< registermodel>)statebind.ToList();

返回Json(stateList);



}

}

catch(例外情况)

{

LogManager。 WriteErrorLog(ex);

objStringBuilder.Clear();

objStringBuilder.AppendLine(Start:StateList,StateList Method);

objStringBuilder .Append(ex.Message);

LogManager.WriteTraceLog(objStringBuilder);

返回null;

}



}



但是thruogh jquery我没有得到停机状态..



Plz帮助...

jquery to bind states in dropdown when country is selected from another dropdown in MVC 4 while registering user..

I have got the states name in one list "stateList" while selecting country name from dropdown through the function "GetStatesList"

[HttpPost]
[AllowAnonymous]
public ActionResult GetStatesList(int countryid)
{
TracFindDALContainer tracFindStates = null;
List<registermodel> stateList = null;
try
{
using (tracFindStates = new TracFindDALContainer())
{
var statebind = (from s in tracFindStates.States
join c in tracFindStates.Countries on s.Id equals c.Id
where s.CountryID == countryid
select new RegisterModel
{
Stateid =s.Id,
StateName =s.StateName });

if (statebind == null)
return Json(null);
stateList = (List<registermodel>)statebind.ToList();
return Json(stateList);

}
}
catch (Exception ex)
{
LogManager.WriteErrorLog(ex);
objStringBuilder.Clear();
objStringBuilder.AppendLine("Start: StateList, StateList Method");
objStringBuilder.Append(ex.Message);
LogManager.WriteTraceLog(objStringBuilder);
return null;
}

}

but thruogh jquery I am not getting states in doropdown..

Plz help...

推荐答案


这篇关于当在MVC中选择国家/地区时,jquery将在下拉列表中绑定状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 18:34