2015-02-11 102 views
-1

所以我在控制器中使用了這種方法,我通過javascript調用,但出現錯誤500:內部服務器錯誤。當我嘗試直接通過我的URL訪問該方法時,要查看問題出在哪裏,我看到該參數始終以空值傳遞。參數仍然爲空,即使當我在URL中輸入時

代碼如下:

控制器(參數EditTimeBeforeIdle應該是一個常規的INT,但我暫時改變了它用於調試目的):

[Authorize] 
public class IdleController : BafcareController 
{ 
    private readonly ISystemUnitOfWork _systemUnitOfWork; 
    private readonly ICurrentUser _currentUser; 

    private readonly User _user; 

    public IdleController(ISystemUnitOfWork systemUnitOfWork, ICurrentUser currentUser) 
    { 
     _systemUnitOfWork = systemUnitOfWork; 
     _currentUser = currentUser; 

     _user = _systemUnitOfWork.UserRepository.GetUserById(_currentUser.User.Id); 
    } 
    public int EditTimeBeforeIdle(int? time) 
    { //<-- Breakpoint here to check, time == null 

     _user.TimeBeforeIdle = time; 
     _systemUnitOfWork.UserRepository.Update(_user); 

     ModelSessionHelper.TimeBeforeIdle = time.Value; 
     return time.Value; 
    } 
} 

}

的URL我直接去是

http://localhost:4891/Idle/EditTimeBeforeIdle/21

因此,你可以看到參數不應該爲空,那爲什麼呢?

親切的問候

+4

你是如何配置路由的? – Patrick 2015-02-11 14:48:00

回答

1

「{控制器}/{行動}/{ID}」,或者使用URL:

http://localhost:4891/Idle/EditTimeBeforeIdle/?time=21 

這可能是你想要做的方式。

+0

謝謝!我是這樣一個白癡-_- – Gravinco 2015-02-11 15:04:31

+0

那麼...沒有好的程序員誕生沒有一個良好的brainfart偶爾 – 2015-02-11 15:22:52

+0

但我有那些經常:-p – Gravinco 2015-02-11 15:23:31

1

將參數重命名爲id。

這是默認綁定在MVC

相關問題