保留 DropDownList 编辑器模板的值
我的视图中有这个,并且效果很好,保留了所选的国家/地区:
<%: Html.DropDownListFor(model => model.CountryId, Model.CountryList ,"Select Country") %>
但是,当我为此创建编辑器模板时,所选的国家/地区不会保留
所以,我将当前视图更改为:
<%: Html.EditorFor(model => model.CountryId,new { countries = Model.CountryList}) %>
然后我像这样创建编辑器模板:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Int64?>" %>
<%= Html.DropDownList(
String.Empty /* */,
(SelectList)ViewData["countries"],
Model
)
%>
I have this on my view and this works well, persisting the country selected:
<%: Html.DropDownListFor(model => model.CountryId, Model.CountryList ,"Select Country") %>
However when I create an editor template for this, the country selected is not persisted
So, I change my current view to this:
<%: Html.EditorFor(model => model.CountryId,new { countries = Model.CountryList}) %>
Then I create my editor template like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Int64?>" %>
<%= Html.DropDownList(
String.Empty /* */,
(SelectList)ViewData["countries"],
Model
)
%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试这样的事情:
父视图中的代码:
编辑器视图中的代码:
%>
我没有编译这个。但你已经了解了总体思路。
I would try something like this:
Code in parent view:
Code in editor view:
%>
I didn't compile this. But you get the general idea.