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?

我在表單中有一個名為'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”,它會自動化到名稱中的屬性。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/04/28/72f6b1d60bc008af91cbe89bac1b59e2.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com