MVC Editor适用于复合模型类型吗?
我想将委托或命令对象作为参数与模型对象一起发送给 EditorFor。我可以使用 viewdata 来发送它,但我非常喜欢它强类型。有什么合理的方法可以做到这一点吗?
这大致就是我希望能够在编辑器模板中执行的操作:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Pair<MyModelType, TheDelegate>>" %>
但是如何将我的委托添加到这样的表达式中?
<%= Html.EditorFor(m => m.MyModelTypeField, "ThatEditor") %>
I would like to send a delegate or a command object as argument to an EditorFor along with the model object. I could use viewdata to send it with, but I would very much like it strongly typed. Is there any reasonable way to do this?
This is roughly what I'd like to be able to do in an editor template:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Pair<MyModelType, TheDelegate>>" %>
But how could I add my delegate to an expression such as this?
<%= Html.EditorFor(m => m.MyModelTypeField, "ThatEditor") %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您修改视图模型并让控制器传递必要的信息,否则您无法以强类型的方式执行此操作。那么
:
另一种可能性是将其作为附加视图数据传递,但不会强类型化:
然后在编辑器模板内:
You can't do this in a strongly typed manner unless you modify your view model and have the controller pass the necessary information. So
and then:
The other possibility is to pass it as additional viewdata but it won't be strongly typed:
and then inside your editor template: