• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

从DropDownList选择值以能够填写字段

用户头像
it1352
帮助1

问题说明

我已经用以下命令填充了一个DropDownList: 型号:

I have populated a DropDownList with the following: Model:

namespace VAGTC.Models
{
    using System;
    using System.Collections.Generic;

    public partial class Organization
    {

        public int OrganizationID { get; set; }
        public string Name { get; set; }

}

控制器:

public ActionResult Index()
{

    ViewBag.DropOrgID = ddp.OrganizationList();
    return View();
}

ViewModel:

ViewModel:

namespace VAGTC.ViewModels
{
    public class OrgDrop
    {
        public Organization organization { get; set; }
        public IEnumerable<Organization> Organizations {get; set;}
    }
}

助手:

    public class DropDownPopulatorController : Controller
    {
        private VAGTCEntities db = new VAGTCEntities();

        public SelectList OrganizationList(int selectedOrg = 0)
        {
            var orgQuery = from d in db.Organizations
                           orderby d.Name
                           select d;
            return new SelectList(orgQuery, "OrganizationID", "Name", selectedOrg);
        }
    }

然后,我只需在索引视图中放入"@ Html.DropDownList("DropOrgID")"即可.

Then, I simply put "@Html.DropDownList("DropOrgID")" in my index view.

我要做的是通过根据DropDownList中选择的内容从数据库中获取数据来填充文本框(尚未实现).但是我无法弄清楚-我感觉好像是要错误地创建和填充下拉列表.

What I have to accomplish is filling in text boxes (which I have not yet implemented) by fetching data from my database depending on what is selected in the DropDownList. But I could not figure this out - I feel as if I went about creating and populating the drop down incorrectly.

我是MVC的新手,正在慢慢学习!我正在逐步进行!现在专注于仅获取SelectedValue.我尝试了多种创建和填充下拉菜单的方法,但这是对我有用的方法.我查找了用于获取SelectedValue的教程,但它似乎与我进行下拉的方式不兼容.具体来说,我找到了这是我的下拉菜单

谢谢!

正确答案

#1

您可以在Controller中的后操作"中以以下方式获取下拉列表的选定值,

You can Get Drop-down's selected value in Post Action in Controller as,

[HttpPost]
public ActionResult Index(FormCollection frm)
{
   var selectedValue = frm["DropOrgID"];
   return View();
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfggch
系列文章
更多 icon
同类精品
更多 icon
继续加载