asp.net-mvc – ASP.Net Html.DropDownList未选择的元素
我有一个使用ASP.Net MVC Beta 5的网站,我刚刚升级到ASP.Net MVC 1.0.我在下拉列表中遇到了所选项目的问题.
跟随的人有一个类似的问题(Html.DropDownList in ASP.NET MVC RC (refresh) not pre-selecting item),但我没有答案(除了它可能是一个错误) 我的控制器方法如下所示: [AcceptVerbs(HttpVerbs.Get)] public ActionResult View(Guid id) { IntegrationLogic logic = new IntegrationLogic(new IntegrationLinq()); CompanyLogic companyLogic = new CompanyLogic(new CompanyLinq()); IntegrationContainer container = new IntegrationContainer(); container.Sources = logic.GetImportSource(id); container.Companies = companyLogic.GetCompanies(); // Returns a IList<company> container.SourceActions = logic.GetAllSourceActions(); // Returns an IList<SourceAction> container.SinkActions = logic.GetAllSinkActions(); container.SuccessActions = logic.GetAllSuccessActions(); container.FailureActions = logic.GetAllFailureActions(); container.Actions = logic.GetAllActions(); container.Watchers = logic.GetAllWatcherActions(); container.ChainActions = logic.GetAllChainActions(); return View("View",container); } 该视图是对模型的强类型如下 public partial class View : ViewPage<IntegrationContainer> {} 视图模板中的问题区域是: <label for="Companies">Company: </label><%=Html.DropDownList("Companies",new SelectList(ViewData.Model.Companies,"id","name",item.CompanyID))%> 我正在创建一个下拉列表,所选项目从未真正被选中 – 这就是问题. “item.CompanyID”是一个Guid,“id”是Guid,“name”是在IList中提供的公司对象中的一个字符串,该对象被保存在ViewData.Model.Companies实例中. 这实际上是一个错误 – 我发现很难理解为什么这仍然存在于ASP.Net MVC …如果这是我已经完成,我将是完全幸福的. 无论如何,建议的工作是什么? 谢谢 解决方法
事实证明,如果您通过Html.DropDownList控件的名称与收集对象名称相同,则会导致ASP.Net MVC出现问题.
所以如果我更改以下代码: <label for="Companies">Company: </label><%=Html.DropDownList("Companies",item.CompanyID))%> 至: <label for="Companies">Company: </label><%=Html.DropDownList("company",item.CompanyID))%> 现在所有的工作.这是因为模型上的收集名称是Model.Companies …. bonkers …还注意到,将控制名称从“公司”更改为“公司”的情况也不起作用(这使得感觉我想) 我可以改变模型,但是大多数是使用Linq-to-SQL构建的,我认为改变Html元素的名称是比较容易的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET MVC 4和会话安全漏洞
- asp.net-mvc – Dotnetopenauth使用自定义身份提
- ASP.NET – 在GridViewRowEventArgs Row.Cells.I
- asp.net – url重写模式中^ ON $和^ OFF $的含义
- 单元测试 – 测试urlhelper的WebApi单元现在为空
- asp.net-mvc – 错误NU1002项目WebApplication1中
- asp.net-mvc – ASP.NET MVC FluentValidation P
- msbuild – 通过TFS 2015部署ASP.NET 5(vNext)
- asp.net-mvc – 在ASP.NET MVC视图中递归
- asp.net-mvc-3 – ASP.NET Web API – NTLM身份验