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 – 32位池和64位池之间的内存使用情况
- asp.net – 如何使一个TextBox控件是多行不可调整大小?
- ASP.net在发布时不会填充服务器表单的action =“”
- asp.net-mvc – MVC捆绑客户端缓存
- asp.net – 在剃刀中等同于End / Response.End?
- asp.net-mvc – MVC DateTime文本框格式化问题
- asp.net-mvc-2 – 强大类型的ActionLink在Asp.Net MVC 2?
- 定期刷新局部视图(ASP.Net MVC)
- asp.net-mvc – Mvc4绑定,缩小和AngularJS服务
- asp.net-mvc – 什么是防伪令牌盐的使用?
- asp.net-mvc – ASP.NET MVC中的Windows Live ID
- asp.net-mvc – ASP.Net MVC是否运行在ASP.NET 2
- asp.net – 避免表格重新提交
- ASP.net没有为某些用户代理生成javascript
- asp.net – 双回发问题
- asp.net – 在.NET Core 1.0 MVC中的视图中使用授
- asp.net-mvc – 为IIS托管的.SVC文件配置XML-RPC
- asp.net-mvc – ASP MVC 3 RequireHttps属性将所
- asp.net – GetExternalLoginInfoAsync()loginIn
- asp.net-mvc – 实现多租户ASP.NET MVC应用程序的
