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

[英]ASP.NET MVC How to specify additional parameters in POST method?

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?


1 个解决方案


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


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”,它會自動化到名稱中的屬性。



粤ICP备14056181号  © 2014-2021