c# - Session item always null in asp.net mvc3 -
the function upload image:
[httppost] public string uploadsingle(httppostedfilebase imagefile) { try { string filesavepath = server.mappath("~/content/temp/" + imagefile.filename); imagefile.saveas(filesavepath); list<string> uploadedfile = (list<string>)httpcontext.session["uploadedfiles"]; if (uploadedfile == null) { uploadedfile = new list<string>(); } uploadedfile.add(filesavepath); httpcontext.session["uploadedfiles"] = uploadedfile; return "success"; } catch (exception e) { return "error"; } } this function work okay, image uploaded. when try see uploaded images.
public string uploadresult() { list<string> uploadedfile = (list<string>)httpcontext.session["uploadedfiles"]; return uploadedfile.count + ""; } when debug, httpcontext.session["uploadedfiles"] return null. please give me help.
use httpcontext.current.session["uploadedfiles"] instead of httpcontext.session["uploadedfiles"]
httpcontext.current.session returns null if there no session available.
Comments
Post a Comment