从DropDownList选择值以能够填写字段
问题说明
我已经用以下命令填充了一个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的教程,但它似乎与我进行下拉的方式不兼容.具体来说,我找到了这是我的下拉菜单
谢谢!
正确答案
您可以在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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22