C#MVC HTML表单标签帖子不会从输入标签发送数据

时间:2016-08-12 13:01:04

标签: c# .net asp.net-mvc

这是来自更大页面的剪辑。

<form method="post" action="/Packlist/EditHdr/1">

<input type="hidden" id="dateAnticipated" value ="01/01/2016" />
<input type="hidden" id="dateActual" value ="08/09/2016" />



<fieldset style="width:25em">
    <legend>Edit:</legend>


 ......

    <div class="PropRow">
        <div class="Name">&nbsp;</div>
        <div class="Value">
            <input type="submit" value="Save" />
            <input type="button" name="Cancel" value="Cancel" onclick="window.location='/Packlist' " />
        </div>
    </div>
</fieldset>
</form>

当我单击“提交”按钮时,我发现EditHdr控制器方法中的FormCollection对象中没有任何内容。但我当然可以采用这种方法。

如果我将表单操作重定向到     http://httpbin.org/ 我看到了帖子:

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "en-US,en;q=0.8", 
    "Cache-Control": "no-cache", 
    "Content-Length": "0", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "Origin": "http://localhost", 
    "Pragma": "no-cache", 
    "Referer": "http://localhost/Packlist/EditHdr/1", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
  }, 
  "json": null, 
  "origin": "......", 
  "url": "http://httpbin.org/post"
}

数据段中的输入字段在哪里?

1 个答案:

答案 0 :(得分:1)

您需要将标记name添加到要在form中提交的字段中。

<input name="dateAnticipated" type="hidden" id="dateAnticipated" value ="01/01/2016" />
<input name="dateActual" type="hidden" id="dateActual" value ="08/09/2016" />