我通過ASP.NET MVC創建了一個簡單的API 4文件路徑:ASP.NET無法解析xml!檢查
public class ActionController : ApiController
{
[WebMethod]
public string getCommunities()
{
try
{
MethodClass method = new MethodClass();
return method.getCommunities();
}
catch(Exception ex)
{
return ex.Message.ToString();
}
}
}
正試圖調用方法類,這個方法:
public string getCommunities()
{
return "bbb";
}
,但不管是什麼原因,我得到這個錯誤:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">cannot parse xml! Check file path</string>
我試着用搜索引擎的錯誤,但一無所獲,也沒有人見過這個錯誤?我該如何解決它?
WebMethod?爲什麼在這裏? –
,因爲我正在計劃通過ajax使用此代碼 – user979331
[WebMethod]對於MVC應用程序不是必需的。頁方法是老派在代碼後面(aspx.cs)頁面做的方式... –