我正在使用Web Api Asp。 Net和想要運行我的控制器全光照的javascript,如:使用javascript調用get方法
JS
function cargarCatalogo() {
apiService.get("../../api/CatalogoRegistro/get/", null,
function (res) {
$scope.Catalogos = res.data.Nombre;
},
errorCatalogo);
}
控制器
[AllowAnonymous]
[HttpGet]
[Route("{catalogo}")]
public HttpResponseMessage Get(HttpRequestMessage request, string catalogo)
{
return CreateHttpResponse(request,() =>
{
HttpResponseMessage response = null;
var cr = _pService.Listar(param => param.Catalogos.Nombre.Equals(catalogo));
IEnumerable<CatalogoRegistroViewModel> crs = Mapper.Map<IEnumerable<CatalogoRegistro>, IEnumerable<CatalogoRegistroViewModel>>(cr);
var version = request.Headers.GetValues("Version").FirstOrDefault();// ServerVariables.Get("HTTP_X_MY_CUSTOM_HEADER_NAME");
List<string> errores = new List<string>();
if(cr==null)
{
errores.Add("El Catalogo no existe");
//response = request.CreateResponse<string>(HttpStatusCode.BadRequest, "El parametro no existe");
}
if(errores.Count>0)
response = request.CreateResponse(HttpStatusCode.BadRequest, new { success = false, errores });
else
{
response = request.CreateResponse<IEnumerable<CatalogoRegistroViewModel>>(HttpStatusCode.OK, crs);
}
return response;
});
}
斜視
<div class="page-head">
<div class="page-title">
<h1>
Catálogos Genéricos
<small>Administrar Catálogos Genéricos de las Aplicaciones</small>
</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<!-- BEGIN Portlet PORTLET-->
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption">
Catálogos Genéricos
</div>
<div class="tools">
<a href="javascript:;" class="collapse" data-original-title="" title=""> </a>
<a href="javascript:;" class="reload" data-original-title="" title="" ng-click="actualizar();"> </a>
<a href="javascript:;" class="fullscreen" data-original-title="" title=""> </a>
</div>
</div>
<div class="portlet-body">
<div class="form-group" ng-model="filterConductores">
<br/>
<div class="row">
<div class="col-md-12">
<div class="col-md-2">
<button id="agregar" type="submit" class="btn blue btn-lg" ng-click="nuevo();">Agregar</button>
</div>
<div class="col-md-2">
<button id="eliminar" type="submit" class="btn blue btn-lg" ng-click="eliminar();">Eliminar</button>
</div>
</div>
<br/>
<br/>
<div class="row">
<div class="col-md-12">
<div class="row margin-top-10 form-horizontal">
<div class="col-md-10 text-right ">
<label class="control-label">Mostrar: </label>
</div>
<div class="col-md-2">
<select class="form-control input-sm" name="Catalogo" id="Catalogo" ng-change="filtro('Estatus')" ng-model="f.Estatus">
<!--ng-options="item.Nombre as item.Nombre for item in EstatusViaje"> -->
<option value="" selected>TODOS</option>
<option ng-repeat="item in Catalogos" value="{{item.Nombre}}" label="{{item.Nombre}}"></option>
</select><br />
</div>
</div>
</div>
<div class=" col-md-12">
<table class="table table-striped table-hover table-bordered dt-bootstrap no-footer" id="tabla_conductores" role="grid" aria-describedby="sample_editable_1_info">
<thead>
<tr>
<th class="hidden"></th>
<th style="width: 200px;"> Codigo </th>
<th> Nombre </th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
但我得到的問題
GET http://localhost:55720/api/CatalogoRegistro/get/ 404 (Not Found)
什麼是我的API的路徑迴環?我不明白
我嘗試這樣做,但我得到'的ReferenceError:catalogo不defined' – Gerardo
那麼,你將需要提供'catalogo'。我不知道你的Angular的觀點。 – Win
我現在在我的問題中張貼我的角度視圖 – Gerardo