Вот мой клиентский код:
Код: Выделить всё
function saveForm() {
let formData = new FormData();
formData.append("name", "john");
$.ajax({
type: "POST",
url: 'Page1.aspx?method=SaveForm',
data: formData,
contentType: false,
processData: false,
cache: false,
success: onSuccessSaveForm,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
Код: Выделить всё
public partial class Page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["method"] != string.Empty && Request.QueryString["method"] != null)
{
Type thisType = this.GetType();
MethodInfo theMethod = thisType.GetMethod(Request.QueryString["method"]);
theMethod.Invoke(this, null);
}
}
}
public string SaveForm()
{
Result result = new Result();
...code
return JsonConvert.SerializeObject(result); -->(*expect to return this)
}
остановимся на theMethod.Invoke(this, null) и вернемся к моему вызову ajax
Результат:
продолжает метод page_load в MasterPage.master.cs и возвращает весь HTML-код в качестве результата
Как передать результат из theMethod.Invoke(this, null) во внешний интерфейс. И, если возможно, не нужно также заходить в MasterPage.master.cs и не обновлять страницу, например, используя [System.Web.Services.WebMethod].
Подробнее здесь: https://stackoverflow.com/questions/784 ... -from-curr
Мобильная версия