RenderAction 生成下拉菜单?
我有一个 mvc 表单,其中包含一个 int ,该 int 应该映射到下拉列表中显示的文本字符串。
MyViewModel
{
...other fields...
int Level { get; set; }
...other fields...
}
是否可以对 Level 字段使用 RenderAction 并从单独的操作生成下拉列表?
我希望这个问题是连贯的,我要戒咖啡了,我的头不在平常的地方。
I'm having a mvc form which among other things contains an int that should be mapped to text strings displayed in a dropdown.
MyViewModel
{
...other fields...
int Level { get; set; }
...other fields...
}
Is it possible to use RenderAction for the Level field and generate the dropdown from a separate action?
I hope this question is coherent, I'm quitting coffee and my head isn't where it usually is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然很多人会建议(正确地)不要这样做,但如果你坚持你可以做类似的事情
,因为你想重用这个下拉列表,你可以接受它的 html name 属性作为
视图中的操作方法参数,你可以写类似的东西
Although many people will advise (rightly so) not to do this but if you insist you can do something like
as you want to reuse this dropdown you can accept its html name attribute as action method parameter
in your view you can write something like