Previous program:
ViewData["msg"] = " {result:true,FileName:"" new FileInfo(Request.Files[0].FileName).Name
"",FileUrl:"" fileurl.Replace(""", "") ""}";
The program after reconstruction:
JsonResult j = Json(new
{
Result = true,
FileName = new FileInfo(Request.Files[0].FileName).Name,
FileUrl = fileurl.Replace("" ", "")
});
ViewData["msg"] = j.Data.ToString();
Obviously, the second way is more readable , the first one is slightly better than the second one in terms of performance, but for programs, performance is only one aspect
In terms of object-oriented programs, its possibility, writing code is not prone to errors, and the rate is also very high Important, therefore, it is recommended to use the Json provided by C# when returning complex string characters, instead of spelling the Json format returned by JS yourself.