开发者

Asp.net MVC 2 CascadingDropDown

开发者 https://www.devze.com 2023-02-07 14:04 出处:网络
Hi, this is my Controller Code: public ActionResult Create() { makelist = new SelectList(db.CountryMasters.ToList(), \"CountryID\", \"CountryName\",1);

Hi, this is my Controller Code:

public ActionResult Create()
{
      makelist = new SelectList(db.CountryMasters.ToList(), "CountryID", "CountryName",1);
        ViewData["CounrtyMaster"] = makelist;

        var modelList = new CascadingSelectList(clientMasterManagement.GetState(makelist.SelectedValue.ToString()), "StateID", "StateName");
        ViewData["StateMaster"] = modelList;

        return View("Create");
} 

and this is my View Code:

<div class="editor-field">
    <%= Html.DropDownList("CountryID", ViewData["CounrtyMaster"] as SelectList)%>
    <%= Html.ValidationMessageFor(model => model.CountryID) %>
</div>

<%= Html.CascadingDropDownList("StateMaster","CountryMast开发者_如何学Pythoner")%>

when I select upper list it's not affecting the second one, can anyone help me here???


User CascadingSelectList function instead of SelectList in your controller action

var makelist = new SelectList(db.CountryMasters.ToList(), "CountryID", "CountryName",1); ViewData["CounrtyMaster"] = makelist;
var modelList = new CascadingSelectList(clientMasterManagement.GetState(makelist.SelectedValue.ToString()), "StateID", "StateName");
ViewData["StateMaster"] = modelList;


Html.CascadingDropDownList is not a standard MVC helper. I take it that you are using Stephen Walther's helper. If so this question will help you out:

ASP.NET MVC - Cascading Drop Down

0

精彩评论

暂无评论...
验证码 换一张
取 消