2012-04-22 78 views
0

我有這個問題,我似乎無法弄清楚我張貼數據,以我的控制器,控制器的聲明看起來是這樣的:。參數字典包含空條目」

public ActionResult Create(string Title, string Description, string Payment, string Adress, string ZIP, float Longitude, float Latitude) 

使用招,發佈數據看起來像這樣

Fiddler posted data

發帖時我收到此錯誤信息:

參數字典包含一個null條目,用於方法System.Web.Mvc.ActionResult的非空類型'System.Single'的參數'Longitude'條目Create(System.String,System.String,System.String,System.String ,'System.String,Single,Single)'在'GjortWebRole.Controllers.MyController'中。可選參數必須是引用類型,可爲空類型,或者聲明爲可選參數。 參數名稱:參數

+0

你能告訴我們你怎麼稱呼這個行動方法嗎? – 2012-04-22 14:01:07

+3

它可能是一個編碼問題。你的瀏覽器/服務器文化是什麼?經度值「15.628」是否符合您的文化?嘗試發送'15,628' – nemesv 2012-04-22 14:20:12

回答

0

如參數表所示,按照經度(float)參數的順序發送城市值(String)。嘗試在經度參數之前將城市參數添加到您的操作方法中。

public ActionResult Create(string Title, string Description, string Payment, string Adress, string ZIP,string City, float Longitude, float Latitude) 

UPDATE

根據您的意見,Create方法聲明應該如下

[HttpPost] 
public ActionResult Create(FormCollection myform) 
{ 
    String Title = myform["Title"];//title is the name of html tag 
    Strign ZIP = myform["ZIP"];//ZIP is the name of html tag 
    . 
    . 
    . 
} 
+0

訂單真的很重要嗎?我將City參數添加到操作方法參數列表中,它與現在的帖子順序相同,但結果相同:/ – 2012-04-22 14:12:37

+0

如何調用此操作方法? – 2012-04-22 14:16:36

+0

通過表單發佈數據調用它,其中「我的」是控制器,「創建」是動作。 '你是否用'HttpPost'屬性修飾'Create'方法?

' – 2012-04-22 14:18:18

2

正如this question提到,MVC並沒有拿出一個ModelBinder的浮出的盒子。如果您希望操作接受浮點參數,則必須創建自己的。