Request .Form returns null

asp.net, c#, html

Solution

try adding name to your input field :

<input  type="text" id="PcId" name="PcId" value=<%=Model.PcId %>

According to The W3C specification, that every form input element should have a name attribute specified. Otherwise that element will not be processed.

http://www.w3.org/TR/html401/interact/forms.html#successful-controls

Problem

I am not able to retrieve the values in my controller, it is returning null. Please help me find out what I have done wrong. below is my 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 my 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(); } ```

Original source