我想要使用AngularJs來使用我的ASP.NET Web API。問題是,我想傳遞可選參數到基於用戶輸入(2 Html文本框)的url,但我不知道如何。
這是我的ASP.NET Web API控制器AngularJs,根據用戶輸入將可選參數傳遞到URL
[Route("api/JobShow/{keyword}/{location}")]
public class JobShowController : ApiController
{
[HttpGet]
public PageResult<sp_JobSearch_Result> Get(ODataQueryOptions<sp_JobSearch_Result> options, string keyword = null, string location = null)
{
ODataQuerySettings settings = new ODataQuerySettings()
{
PageSize = 20
};
JobWindow obj = new JobWindow();
IQueryable results = options.ApplyTo(obj.showJobs(keyword, location).AsQueryable(), settings);
return new PageResult<sp_JobSearch_Result>(
results as IEnumerable<sp_JobSearch_Result>,
Request.GetNextPageLink(),
Request.GetInlineCount());
}
}
這是我AngularJS控制器的url
angular.module('JobSearch.SiteController', []).controller('JobSearchCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get('/api/JobShow').success(function (data) {
$scope.model = data;
});
}]);
例則是.../API/JobShow /的Java /多倫多。謝謝你們。
是你在談論的是可選參數的路徑參數'keyword'和'location'? – kazenorin
是的,他們是。我在我的API控制器的屬性路由中顯示它。 – Iman