Previous programs:
Copy codeThe Code is as follows:
ViewData ["msg"] = "{result: true, FileName: \" "+ new FileInfo (Request. Files [0]. FileName). Name +
"\", FileUrl: \ "" + fileurl. Replace ("\" "," ") + "\"}";
The restructured program:
Copy codeThe Code is as follows:
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 method is more readable, and the first method is slightly better than the second method in terms of performance. However, for programs, performance is only one aspect.
For Object-oriented Programs, the possibility of writing code is not easy to error rate is also very important. Therefore, we recommend that you use the Json provided by C # When returning complex notebooks, you do not need to spell the Json format returned by JS.