c# - Request .Form returns null -
i not able retrieve values in controller, returning null. please me find out have done wrong.
below code
index.aspx
<form id="form1" method="post" action="/sample/index" enctype="multipart/form-data"> <div> <input type="text" id="pcid" value=<%=model.pcid %> /></div> <input type="file" value="browse" id="file"/> <input type="submit" id="submit" value="save"/></div> </form>
and in controller
[httppost] public actionresult index(httppostedfilebase file) { string pcid = request.form["pcid"]; list<string> fileconfigdata = new list<string>(); if (file != null && file.contentlength > 0) { string folderpath = mpath.getfolderpath(); var filename = path.getfilename(file.filename); string filepath = server.mappath(folderpath + pcid) + "\\" + filename; file.saveas(filepath); } return view(); }
try adding name input field :
<input type="text" id="pcid" name="pcid" value=<%=model.pcid %>
according w3c specification, every form input element should have name attribute specified. otherwise element not processed.
http://www.w3.org/tr/html401/interact/forms.html#successful-controls
Comments
Post a Comment