如果我以这种方式设计我的控制器:
$(document).ready(function(){
$.post('ajax/name.php', {name: name}, success = function(data) {
var options = "";
for(var i = 0; i < data.length; i++) {
options += "<option value='" + data[i].toLowerCase() + "'>" + data[i] + "</option>";
}
var selector = document.getElementById('name-data');
selector.innerHTML = options;
selector.removeAttribute('disabled'); //enable the selector again
}
});
这会有用吗?
答案 0 :(得分:1)
我希望结构更类似于此:
[RoutePrefix("item")]
public class ItemController : ApiController
{
[HttpGet]
[Route("dosomething")]
public void DoSomething(Item item)
{ }
[HttpGet]
[Route("dosomethingnicer")]
public void DoSomethingNicer(Item item)
{ }
[HttpGet]
[Route("dosomethingelse")]
public void DoSomethingElse(Item item)
{ }
}
答案 1 :(得分:0)
我在很多控制器中以这种方式使用Web Api 2:
[HttpGet]
[Route("~/api/{version}/research/export")]
public IHttpActionResult Export(){
do stuff...
}
[HttpPost]
[Route("~/api/{version}/research/list")]
public IHttpActionResult List()
{
do stuff...
}
我使用完整的api路径描述,它没有任何问题。