首先,是否可以使用ajax将数据发布到.netcore 2.0页面?其次,Razor页面(.Netcore 2.0)替代了MVC方法吗?替代方法?在.netcore 2.0中使用Ajax发送数据到Razor页面

$('#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 { 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();

}

}

+0

你有什么问题?不,纠正我,如果我错了.NET Core 2.0使用MVC 6 Razor语法...不能替代 –

+0

当我发布数据到MVC控制器时,数据通过我的控制器方法,但是当我尝试使用它。 netcore 2.0剃刀页面的方法不会被调用。 –

+0

我不确定是否支持'Route'属性......它似乎是[未解决的问题](https://github.com/aspnet/Mvc/issues/6605)。 –

更多推荐