2016-07-25 30 views
1

我有一個控制器象下面這樣:GUID參數總是空在控制器的ActionResult

public async Task<IHttpActionResult> MyControllerMethod(string currency = null, 
                  string edition = null, 
                  int? systems = null, 
                  string version = null, 
                  Guid? entitlementid = null) 
{ 
//Code here 
} 

當我從這個URL,執行該控制器:

http://*:*/MyController/MyControllerMethod/?currency=eur&edition=DSSTANDARD&systems=50&version=6.3/ 

所有的方法的參數具有值如下圖所示:

currency = eur 
edition = DSSTANDARD 
systems = 50 
version = 6.3 

但是,如果我做同樣的添加最後一個參數:

...&entitlementid=B5630B37-0820-4EB0-8A2A-000C44885590/ 

然後,前3個值具有值從URL但entitlementid總是null。 可能是什麼問題?

路由配置

config.Routes.MapHttpRoute( 
    name: "DefaultApi", 
    routeTemplate: "{controller}/{action}/{id}", 
    defaults: new { id = RouteParameter.Optional } 
); 
+0

http://stackoverflow.com/questions/16605632/mvc-querystring-with-guid-returns-404 –

+0

@KartikeyaKhosla我沒有 eg16

+0

這看起來像一個WebAPI調用。你能顯示路由配置嗎? – Nkosi

回答

1

你包括在查詢字符串

...&entitlementid=B5630B37-0820-4EB0-8A2A-000C44885590/ 

結束一個額外的斜槓/這是造成Guid結合變得無效。如果刪除斜槓併發出請求,則會填充entitlementid。如預期

http://*:*/MyController/MyControllerMethod/?currency=eur&edition=DSSTANDARD&systems=50&version=6.3&entitlementid=B5630B37-0820-4EB0-8A2A-000C44885590

應該工作。