C# 创建没有MVC的小型单页Web API?
在C语言中,我限制使用一个.aspx文件和相应的脚本文件 我不知道如何使用这些WebMethods来实现以下目标:C# 创建没有MVC的小型单页Web API?,c#,asp.net,ajax,webmethod,C#,Asp.net,Ajax,Webmethod,在C语言中,我限制使用一个.aspx文件和相应的脚本文件 我不知道如何使用这些WebMethods来实现以下目标: Request Header: "http://localhost:8888/singlepage.aspx/file/8/items", Type: "POST", Data: {Description,Price} [WebMethod] public static void SaveDescriptionAndPrice(string description, decima
Request Header: "http://localhost:8888/singlepage.aspx/file/8/items",
Type: "POST",
Data: {Description,Price}
[WebMethod]
public static void SaveDescriptionAndPrice(string description, decimal price)
{
// Do something here to save values
}
$(document).ready(function() {
$.ajax({
type: "POST",
url: "singlepage.aspx/SaveDescriptionAndPrice",
data: "{'description':'This is a fake description.', 'price':12.99}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// Do something interesting here.
}
});
});
没有MVC也可以吗?您可以使用ASP.NET AJAX页面方法创建页面托管的web服务方法,如下所示:
Request Header: "http://localhost:8888/singlepage.aspx/file/8/items",
Type: "POST",
Data: {Description,Price}
[WebMethod]
public static void SaveDescriptionAndPrice(string description, decimal price)
{
// Do something here to save values
}
$(document).ready(function() {
$.ajax({
type: "POST",
url: "singlepage.aspx/SaveDescriptionAndPrice",
data: "{'description':'This is a fake description.', 'price':12.99}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// Do something interesting here.
}
});
});
现在在.aspx页面中,您可以使用jQuery.AJAX函数调用ASP.NET AJAX页面方法,如下所示:
Request Header: "http://localhost:8888/singlepage.aspx/file/8/items",
Type: "POST",
Data: {Description,Price}
[WebMethod]
public static void SaveDescriptionAndPrice(string description, decimal price)
{
// Do something here to save values
}
$(document).ready(function() {
$.ajax({
type: "POST",
url: "singlepage.aspx/SaveDescriptionAndPrice",
data: "{'description':'This is a fake description.', 'price':12.99}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// Do something interesting here.
}
});
});
注意:我对数据的值进行了硬编码,但是您可以创建一个JavaScript对象来保存这些值并对它们进行字符串化,或者使用jQuery从DOM元素中选择这些值。您可以在MVC之外使用路由引擎,这样您就可以在webforms中使用路由 关于这个主题有很多演练,但这一次是从MS
这就是我要找的。。。web表单路由asp.net考虑客户端框架Ember、Angular等。+0:虽然建议有效,但似乎对OP不可用:我限制使用一个.aspx文件和相应的脚本文件。这似乎是唯一的方法,使用json传递任何额外参数。有没有教程介绍如何从头开始并将其托管在IIS上,以便外部人员可以访问API go get数据?