MVC3 复选框列表
可能的重复:
MVC3.0中的CheckboxList
嗨,我有两门课书和作者,我想要的是当你添加一本书会出现作者列表,您可以选择其中的一个或多个。我认为最好的方法是使用清单,但没有找到使用 mvc3 执行此操作的方法。但读过一些例子但不明白,我只是从 mvc 开始,所以如果有人能告诉我如何制作这些,我将不胜感激
public class Book
{
public int IdBook {get; set;}
public string Title {get; set;}
public List<author> Authors {get; set;}
}
public class Author
{
public int IdAuthor{get; set;}
public string Name {get; set;}
}
Possible Duplicate:
CheckboxList in MVC3.0
Hi I have two classes book and author and I want is that when you add a book appears a list of authors and you can select one or more of one. the best way to do this I think is a checklist but not found a way to do this with mvc3. but have read some examples and not understood, I just starting with mvc so if someone can tell me how could I make these I would greatly appreciate
public class Book
{
public int IdBook {get; set;}
public string Title {get; set;}
public List<author> Authors {get; set;}
}
public class Author
{
public int IdAuthor{get; set;}
public string Name {get; set;}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以向您的作者添加一个
Selected
布尔属性,以便了解他是否被选为给定的书籍:然后:
并在视图中:
You could add a
Selected
boolean property to your Author in order to know whether he was selected for the given book or not:and then:
and in the view:
您需要向您的作者模型视图类添加一个
bool Selected
字段(或为其创建一个模型视图类,以便您可以存储此类元数据),然后就可以了像往常一样正常绑定:You'll need to add a
bool Selected
field to your author model-view class (or create a model-view class for it so you can store this kind of meta-data), and then it's just normal binding like usual: