まず、ajaxを使用して.netcore 2.0ページにデータを投稿することは可能ですか?.netcore 2.0のAjax to Razorページを使用したデータの投稿
第2に、Razorページ(.Netcore 2.0)はMVCのアプローチに代わるのですか?代わりのアプローチ?
$('#sum').click(function() {
$.ajax({
type: 'POST',
url: '/Manifest/Sum/3/5',
success: function (result) {
alert("Succes y'all");
}
});
});
public class IndexModel : PageModel
{
private readonly CloudSolution.Models.DomainData.ManifestContext _context;
public IndexModel(CloudSolution.Models.DomainData.ManifestContext context)
{
_context = context;
}
public IList<ManifestViewModel> ManifestViewModel { get;set; }
public IActionResult HelloAjax()
{
return Content("Hello from the controller!", "text/plain");
}
[HttpPost, Route("/Manifest/Sum/{firstNumber}/{secondNumber}")]
public IActionResult Sum(int firstNumber, int secondNumber)
{
return Content((firstNumber + secondNumber).ToString(), "text/plain");
}
public async Task OnGetAsync()
{
ManifestViewModel = await _context.ManifestViewModel.ToListAsync();
}
}
何が問題なのですか?私が間違っていれば私を修正してください。.NET Core 2.0はMVC 6 Razorの構文を使用しています...代用品ではありません – 12seconds
MVCコントローラにデータを投稿すると、データはコントローラメソッドに渡されますが、 netcore 2.0カミソリのページは、メソッドが呼び出されない。 – Decoder94
'Route'属性がまだサポートされているかどうかはわかりません。それは[未解決の問題](https://github.com/aspnet/Mvc/issues/6605)のようです。 –