Previous programs:
Copy Code code as follows:
viewdata["msg"] = "{result:true,filename:\" "+ New FileInfo (request.files[0). FileName). Name +
"\", fileurl:\ "" + FILEURL. Replace ("\" "," ") +" \ "}";
The program after refactoring:
Copy Code code 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 way is more readable, the first kind of performance is slightly better than the second, but for the program, performance is only one aspect
In the case of object-oriented programs, it is also important to write code that is not error-prone, so it is recommended that you use the JSON provided by C # when returning complex note characters without having to spell out the JSON format returned by JS.