将验证添加到 EditorTemplate 中的下拉列表
我试图找到一种好方法来通过将 UiHint“DropDown”指定为 ViewModel 的属性,然后仅使用 HtmlHelper EditorFor 通过通用 EditorTemplate 呈现下拉列表,以便它可以跨解决方案使用。我在 Tom Schreck 此处 找到了一个非常好的方法,效果很好。唯一使它不完美的是下拉列表不是验证的一部分。如果我想将“选择”选项(在 EditorTemplate 中手动添加)作为默认选项,并且未选择任何值,则会导致错误。我相信这是因为 DropDownList 不是从 DropDownListFor - Helper 创建的?我知道 Tom 写道他尝试过这一方法,但是没有办法使用自定义值将项目添加到循环中的 SelectList 中吗?我无法做到这一点,因为我是初学者,但我认为如果可以在验证中包含下拉列表,那就太好了。这样您就可以填充控制器中的 selectList 并保持与其他属性相同的格式。抱歉我的词汇量,正如我所说,我是初学者。但我希望你明白我的意思。
如果有人帮助我解决这个问题,我将非常感激,因为我觉得我已经尝试了一切..
问候 max
I am trying to find a good way to have a dropdownlist by specifying UiHint "DropDown" to the property of the ViewModel and then just using HtmlHelper EditorFor to render the dropdown via an generic EditorTemplate so that it can be used across solutions. I found a very good approach by Tom Schreck Here It works fine. The only thing from keeping it from being perfect is that the dropdownlist is not part of the validation. If I would like to have a "choose" option (added manually in the EditorTemplate) as default and no value is chosen it results in an error. I believe it's because the DropDownList is not created from the DropDownListFor - Helper? I know that Tom wrote that he tried that one, but is there no way of adding items to the SelectList in the loop with the custom values? I cannot do it since I'm a beginner but I think it would be really great if the dropdown could be inlcuded in the validation. This way you could populate the selectList in the controller and keep the same format as the other properties. Sorry for my vocabulary, as I said, I'm a beginner. But I hope you understand what I mean.
I would really appreciate if someone helped me to solve this as I feel I have tried everything..
Regards max
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论