Asp.net MVC 2 级联下拉

发布于 2024-10-14 20:29:07 字数 803 浏览 0 评论 0原文

嗨,这是我的控制器代码:

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");
} 

这是我的视图代码:

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

<%= Html.CascadingDropDownList("StateMaster","CountryMaster")%>

当我选择上面的列表时,它不会影响第二个列表,任何人都可以在这里帮助我吗???

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","CountryMaster")%>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑白记忆 2024-10-21 20:29:07

在控制器操作中使用 CascadingSelectList 函数而不是 SelectList

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;

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;
独孤求败 2024-10-21 20:29:07

Html.CascadingDropDownList 不是标准的 MVC 帮助器。我认为您正在使用 斯蒂芬·瓦尔特的助手。如果是这样,这个问题将帮助您:

ASP.NET MVC - Cascading Drop Down

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文