ASP.NET MVC模型绑定到一个列表 [英] ASP.NET MVC Model Binding into a List

查看:139
本文介绍了ASP.NET MVC模型绑定到一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET MVC的网站,一个功能的一部分,允许用户输入的时间时,一定场地是开放的。

In my ASP.NET MVC site, part of a feature allows the user to enter the hours when a certain venue is open.

我已经决定在VenueHours表中的这些时间存储在我的数据库,用FK-到PK关系到场地表,以及星期几,OpeningTime和ClosingTime参数。

I've decided to store these hours in a VenueHours table in my database, with a FK-to-PK relationship to a Venues table, as well as DayOfWeek, OpeningTime, and ClosingTime parameters.

在我看来,我想允许用户仅输入他们了解的时代;换句话说,有些天不得为一个地点填充。我想创建复选框,用户可以检查以启用DAYOFWEEK的OpeningTime和ClosingTime字段的复选框属于

In my View, I want to allow the user to only input the times they know about; in other words, some days may not be filled in for a Venue. I'm thinking of creating checkboxes that the user can check to enable the OpeningTime and ClosingTime fields for the DayOfWeek that the checkbox belongs to.

我的问题是关于如何将这些信息传递给我的HttpPost控制器动作

据我所知,可以在(7),我当然可以只写了7可为空VenueHour参数代入我的行动传递的最大天量,但我敢肯定有一个更好的办法。

As I know the maximum amount of Days that can be passed in (7), I could of course just write 7 nullable VenueHour parameters into my Action, but I'm sure there's a better way.

我可以采用某种绑定查看信息为传递给我的动作列表?这也将帮助我,如果我碰上一个场景,没有限制多少信息的用户可以填写。

Can I somehow bind the View information into a List that is passed to my Action? This will also help me if I run into a scenario where there is no limit to how much information the user can fill in.

推荐答案

斯科特Hanselman的发布了<一个href=\"http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx\">very有关如何好文章使用集合,数组和字典默认模型联交易。这是伟大的,如果你不想编写自定义模型绑定,虽然编写自定义模型绑定不是什么大不了的事。

Scott Hanselman posted a very good article about how the default model binder deals with collections, arrays and dictionaries. It's great if you don't want to write a custom model binder, although writing a custom model binder isn't that big a deal.

这篇关于ASP.NET MVC模型绑定到一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆