ASP.NET MVC ViewModel 保存列表和列表“图像或 YouTube URL”
我发布这个问题是因为我不知道执行以下操作的最佳/正确方法。
我的队友(设计师)给我发送了一个漂亮的设计,其中包括一个用于添加新物品(用于拍卖)的向导。用户必须填写所有必需的详细信息,包括标题、描述、起始价格...等以及标签列表(最多 4 个标签 - 从数据库中选择,将使用自动完成)以及标签列表最多 3 个图像/youtube url(为了更好地解释,请查看此图像:http://i55.tinypic.com/2v11zzr.png)
好的,我想出了应该如何执行向导(参考:如何使用 ASP.Net MVC 制作向导),但我不确定如何收集列表和图片/网址。这就是我的想法:
对于图像/url,我应该创建一个父视图模型,两个子类(ImageViewModel 和 YoutubeUrlViewModel)将从其中继承,然后在解析帖子数据时在控制器操作中 对于图像/url,我应该创建一个父视图
现在关于列表,我不确定是否应该在视图模型中包含一个列表,或者是否应该包含 4 个表示标签的字符串属性(同样适用于图像/url 列表)。
那么最好的方法是什么?
I'm posting this question because I do not know the best/correct way of doing the following.
My team-mate (the designer) sent me a good looking design that includes a wizard for adding new items (for auction). The user has to fill in all the required details which include the title, description, starting price...etc AND a list of tags (up to 4 tags - chosen from the database, will use auto complete) as well as a list of up to 3 images/youtube url's (for the sake of better explanation check this image out: http://i55.tinypic.com/2v11zzr.png)
Ok so I figured out how I should do the wizard ( reference: how to make a wizard with ASP.Net MVC) but I'm not sure about how to collect the lists and the images/url's. Here's what I'm thinking:
For the images/url's, I should create a parent view model from which two sub-classes (ImageViewModel & YoutubeUrlViewModel) would inherit from and then in the controller action when I parse the post data, I would check to see the instance of the parent view model and act accordingly.
Now about the lists, I'm not sure whether I should include a List in my view model or whether I should include 4 string properties representing the tags (the same will apply to the list of images/url's).
So what's the best way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并 Haacked 来救援: http://haacked .com/archive/2008/10/23/model-binding-to-a-list.aspx
:)
And Haacked to the rescue: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
:)