MVC3 上的 Html.EditorFor 问题
我有一个带有表单的视图,该表单被输入到名为 AddEditItemVM 的视图模型中。该视图模型具有以下属性:
public List<Category> Categories{get;set;}
我尝试的是两件事:
为我的视图模型的通用类别列表中的每个类别渲染一个复选框。
当表单发布时,在我的控制器操作中接收实例化的属性类别(进入 AddEditItemVM 的实例)
关于第一点,我想使用任何帮助程序(如果存在) )呈现一个使用 lambda 表达式(如 (m=>m.Categories))的复选框组,而不是将带有 foreach 的复选框呈现到视图中。
关于第二点,我读到 MVC 中有一个功能称为自定义模型绑定程序。它们从 ValueProviders(查询字符串、cookie 或表单值)获取值,并创建必要的实例,将其传递给表单发布后调用的特定操作。我是否应该创建一个自定义模型绑定器以便接收实例化的属性类别?
I have a view with a form that's is typed to a viewmodel called AddEditItemVM. This viewmodel has the following property:
public List<Category> Categories{get;set;}
What im trying is two things:
Render a checkbox foreach Category in the generic category list of my viewmodel.
Make that when the form is posted receive, in my controller action, the property Categories instantiated (into the instance of AddEditItemVM)
About the first point, i would like to use any helper (if exists) that renders a group of checkboxes using lambda expressions like (m=>m.Categories), instead to render the checkbox with a foreach into the view.
About the second point, i read that there is one feature in MVC called Custom Model Binders. These get values from ValueProviders (querystring, cookies, or Form values) and creates the necessary instances passing it to specific action called after a form was posted. Should i create one custom model binder in order to receive my property Categories instantiated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能有效
MVC3.0中的CheckboxList
This might work
CheckboxList in MVC3.0