現在、MVC Webアプリのユーザーは、サーバーに対して一連のajax呼び出しを行うことができます。現在、グローバルラッパー/ハンドラーメソッドを使用せずに、それらすべてを一意に処理しています。これを変更したいのですが、C#の関数デリゲートの経験はあまりありません。
理想的には、次のように設計する必要があります。
public class GenericService
{
public PageViewModel EditPage(PageViewModel model)
{
....
}
public JsonResult JsonAjaxRequest(Func<Object, Object> serviceCall, Object data)
{
try
{
return new JsonResult() { Data = new { status = "ok", data = serviceCall(data) } };
}
catch
{
return new JsonResult() { Data = new { status = "error", message = "The server encountered an unknown error." } };
}
}
これでコントローラーに次のコードがあります。
private readonly GenericService _service;
public JsonResult PageEdit(PageViewModel model)
{
return Json(_service.JsonAjaxRequest(x=>_service.EditPage(model), model));
}
cannot convert from method group to system.func<object, object>
エラーとコンパイルエラーが発生し続けますが、そのinvalid arguments
理由はわかりません。お知らせ下さい。