[asp.net-mvc]C# MVC HTML 表单标记后不将数据从输入标签发送

标签: Asp.net-MVC .Net C#
发布时间: 2016/10/9 4:17:05
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

这是从很多更大的页面截图的步骤。

<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 控制器的方法。 但我可以肯定我打这种方法。

如果我将窗体操作重定向到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:

你需要添加标记 name 到你想要在提交的字段 form

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