2016-12-14 88 views
0

我已經使用MVC模板和具有MVC和Web API的核心參考創建了一個新的Web應用程序。來自ASP.NET MVC5應用程序的Web API調用

我想通過Web API控制器處理所有的業務邏輯。我有一個登錄頁面視圖,表單提交的地方我想用表單數據調用Web API方法。

Login.cshtml

<form action="/api/Authorization/Login" method="post"> 
<div> 
    UserName: <input type="text" name="UserName" id="UserName" value="" /> 
</div> 
<div> 
    Password: <input type="password" name="UserPassword" id="UserPassword" value="" /> 
</div> 
<div> 
    <input type="submit" name="BtnSubmit" value="Login" /> 
</div> 

我已經加入名爲「授權」和上述表格提交控制器文件夾中的Web API控制器,我不能夠達到方法'登錄'。

授權的Web API控制器:

public class AuthorizationController : ApiController 
{ 
    public ActionResult Login(string UserName, string UserPassword) 
    { 
     // method logic 
    } 
} 

在表單提交以下屏幕結束了, enter image description here

請讓我知道我失去了什麼在這裏,這樣我就可以到達下定義的方法api控制器?

還沒有添加任何新的路線CONFIGS,目前在webApiConfig.cs唯一的配置是,

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

回答

相關問題