如何为ASP.NET MVC中包含许多字段的视图实现“创建”控制器操作

时间:2021-04-21 04:09:18

I'm new to ASP.NET MVC so this may be a stupid question.

我是ASP.NET MVC的新手,所以这可能是一个愚蠢的问题。

I have an account object that has many parameters. I've figured out a strategy to break this down into a "wizard"-like interface that will walk a user through collecting the required fields to create the initial business objects. It will then step through pages to collect other, optional, parameters. This way the user isn't faced with a single page on which they have to enter 30 things (I'm probably exaggerating the number, but you get the idea).

我有一个帐户对象,有很多参数。我已经找到了一种策略,可以将其分解为类似“向导”的界面,该界面将引导用户收集必要的字段以创建初始业务对象。然后,它将逐步执行页面以收集其他可选参数。这样用户就不会面对他们必须输入30个内容的单个页面(我可能夸大了这个数字,但你明白了)。

Still, the first page is going to have 10-12 items that the user needs to fill out before I can fill in all the required fields on the 2-3 business objects that accompany a successful registration. Basically, a new user needs to both get an account AND register for an event at the same time, thus the number of items.

尽管如此,第一页将有10-12个项目,用户需要填写这些项目才能填写成功注册后的2-3个业务对象的所有必填字段。基本上,新用户需要同时获得帐户并注册事件,因此需要注册项目数。

In ASP.NET MVC it appears that all of my form parameters map onto method parameters in the controller method. Knowing that methods with lots of parameters are considered a code smell that ought to be refactored out, I'm wondering if there is a different way to accomplish this or if I'm stuck with a controller method that has a one-to-one mapping between form parameters and method parameters.

在ASP.NET MVC中,似乎所有表单参数都映射到控制器方法中的方法参数。知道具有大量参数的方法被认为是应该重构的代码气味,我想知道是否有不同的方法来实现这一点,或者我是否坚持使用具有一对一的控制器方法表单参数和方法参数之间的映射。

Is there a good known pattern that I've missed in my Google searches to solve this problem?

我在Google搜索中错过了一个众所周知的模式来解决这个问题吗?

3 个解决方案

#1


3  

Have a look at Scott Gu's post on form posting scenarios. In particular you want to look at model binders.

看看Scott Gu关于表单发布方案的帖子。特别是你想看模型粘合剂。

#2


0  

There is always the old...

总有旧...

Request.Form("key");

#3


0  

Ditto joelc : MODEL BINDERS. His link points well.

Ditto joelc:MODEL BINDERS。他的联系很好。

#1


3  

Have a look at Scott Gu's post on form posting scenarios. In particular you want to look at model binders.

看看Scott Gu关于表单发布方案的帖子。特别是你想看模型粘合剂。

#2


0  

There is always the old...

总有旧...

Request.Form("key");

#3


0  

Ditto joelc : MODEL BINDERS. His link points well.

Ditto joelc:MODEL BINDERS。他的联系很好。