1, problem description
MVC gets all the picture information from one path, and the Ajax method is as follows:
functiongetimages (day) {varYear = $ ("#selYear"). Val (); varMonth = $ ("#selMonth"). Val (); Selday=Day ; varDate = year + "." + month + "." + (Day < 10?) "0" +day:day); $("#selInfo"). text (date); $("#fileContainer"). HTML (""); $.ajax ({URL:' @Url. Content ("/medoffice/photo/imagelist") ' + '? path= ' +date, type:' GET ', DataType:' Text/json ', Success:function(data) {alert (data); }, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {console.log (XMLHttpRequest); alert (XMLHttpRequest); } }); }
The call execution returns the following result:
2, problem analysis
Change the JSON to Jsonresult and set to:
Jsonrequestbehavior = jsonrequestbehavior.allowget//Plus this sentence
3. Correct Request method
PublicJsonresult ImageList (stringpath) {List<FileInfoViewModel> files =NewList<fileinfoviewmodel>(); Try { vardatetime =datetime.parse (path); varMyPath = path. Replace (DateTime. Year +".",""); varDestPath ="~/alldocuments/"+ DateTime. Year +"/"+MyPath; DestPath=Server.MapPath (DestPath); if(Directory.Exists (DestPath)) {foreach(stringFilePathinchDirectory.GetFiles (DestPath)) {Fileinfoviewmodel Model=NewFileinfoviewmodel {Path=filepath, Name=path.getfilenamewithoutextension (filepath)}; Try { varFileInfo =NewFileInfo (filepath); Model. Size=fileInfo.Length.ToString (); Model. Date= FileInfo.CreationTime.ToString ("YYYY-MM-DD HH:mm:ss"); } Catch(Exception e) {loghelper.error (e); } } } return NewJsonresult () {Data=New{result=0, Messate="", the data=files}, Jsonrequestbehavior=Jsonrequestbehavior.allowget}; } Catch(Exception e) {loghelper.error (e); return NewJsonresult () {Data=New{result= - About, Messate=e.message, Data=files}, Jsonrequestbehavior=Jsonrequestbehavior.allowget}; } }
This request has been blocked because sensitive information is disclosed to third-party Web sites when used in a GET request. To allow a GET request, set Jsonrequestbehavior to Allowget.