注意前端向後臺傳輸數據時,儘量將實體字段類型定義爲string,如果定義爲具體數據類型,會增大出錯機率,尤其是通過ajax傳輸數據時
//這麼寫總是接收不到數據
public class PPerModel
{
public int PermissionID
{
get;
set;
}
public long ViewID
{
get;
set;
}
public int OprateID
{
get;
set;
}
public bool IsShow
{
get;
set;
}
}
後臺接收數據方法爲
[HttpPost]
public async Task<string> PositionModelRright([FromBody] List<PPerModel> models)
{
NormalResult result = new NormalResult();
if (models == null)
{
result.Result = true;
result.Message = "沒有需要授權的模塊!";
return JsonConvert.SerializeObject(result);
}
return JsonConvert.SerializeObject(result);
}