0
當我在網上探索關於使用asp.net核心構建REST API的文章和內容時,我發現剃鬚刀網頁並不常用於前端。他們大多專注於處理來自服務器的api數據(例如:$ http.get,$ http.post)的Angular 1 & & 2。我只是想知道是否有任何文章介紹瞭如何使用純粹的剃刀網頁作爲處理web api的前端,或者是否有任何方法可以正確使用.net core?使用帶有Razor語法的ASP.NET Core構建REST API
對於前:
[Route("api/students")]
public class StudentsController : Controller
{
private IStudentRepository _repository;
public StudentsController(IStudentRepository repository)
{
_repository = repository;
}
[HttpGet("")]
public IActionResult Get()
{
var results = _repository.GetAllStudents();
return Ok(Mapper.Map<IEnumerable<StudentViewModel>>(results));
}
,取而代之的採用了棱角分明的$ HTTP服務的視圖來呈現,
$http.get("/api/students")
.then(function (response) {
...
}
有沒有呈現在Razor視圖API方法?
這不是剃鬚刀的用途。它是在服務器上執行的HTML渲染引擎。它不會執行javascript代碼來調用API。您最終需要編寫代碼來完成此操作。您仍然可以使用Razor來創建您的HTML頁面,但我認爲如果您使用除Razor以外的其他內容編寫該部分,則會更好。 – MichaelDotKnox
感謝您的評論。這是否意味着我應該使用jQuery等其他語言編寫用於在剃刀網頁中集成web api的語言? (如果我不打算使用角度等)是[this](http://www.mikesdotnetting.com/article/261/integrating-web-api-with-asp-net-razor-web-pages)方法.net核心仍然相關? – pavilion