ASP.NET MVC如何在POST方法中指定其他参数?

时间:2021-12-24 21:34:02

in my MVC application I have a controller (ProjectController) which has an action (create). The create function accepts a projectEntity (custom 3d party datalayer component) as a parameter. The framework automatically binds the entered form values to the projectEntity object.

在我的MVC应用程序中,我有一个控制器(ProjectController),它有一个动作(创建)。 create函数接受projectEntity(自定义3d派对数据层组件)作为参数。框架自动将输入的表单值绑定到projectEntity对象。

This is the create-function signature:

这是创建函数签名:

<AcceptVerbs(HttpVerbs.Post)> _
Function Create(<Bind(Exclude:="Id")> ByVal projectToCreate As BLL.projectEntity) As ActionResult
End Function

I have a field called 'requestDate' in the form. How can I specify the POST method so that it passes the projectToCreate object and the additional 'requestDate' from the form?

我在表单中有一个名为'requestDate'的字段。如何指定POST方法,以便它从表单传递projectToCreate对象和附加的“requestDate”?

1 个解决方案

#1


simply add your additional 1-1 parameters after your first (object) parameter...

只需在第一个(对象)参数后添加额外的1-1参数...

 _
Function Create( ByVal projectToCreate As BLL.projectEntity, ByVal requestData As Nullable(Of Int)) As ActionResult
End Function

I usually will set types as input parameters to nullable. Only the first object will get mapped without other parameter names... if you have a signature with say (object A, object B) in your form, you can use name="someprop" which will get automapped to A.someprop, or you can use name="B.someprop" and it will automap, to the property within the name.

我通常会将类型作为输入参数设置为可空。只有第一个对象将被映射而没有其他参数名称...如果你的表单中有一个带有说(对象A,对象B)的签名,你可以使用name =“someprop”,它将被自动化到A.someprop,或者你可以使用name =“B.someprop”,它会自动化到名称中的属性。

#1


simply add your additional 1-1 parameters after your first (object) parameter...

只需在第一个(对象)参数后添加额外的1-1参数...

 _
Function Create( ByVal projectToCreate As BLL.projectEntity, ByVal requestData As Nullable(Of Int)) As ActionResult
End Function

I usually will set types as input parameters to nullable. Only the first object will get mapped without other parameter names... if you have a signature with say (object A, object B) in your form, you can use name="someprop" which will get automapped to A.someprop, or you can use name="B.someprop" and it will automap, to the property within the name.

我通常会将类型作为输入参数设置为可空。只有第一个对象将被映射而没有其他参数名称...如果你的表单中有一个带有说(对象A,对象B)的签名,你可以使用name =“someprop”,它将被自动化到A.someprop,或者你可以使用name =“B.someprop”,它会自动化到名称中的属性。