ASP.net C# can't read posted form element

血红的双手。 提交于 2019-12-12 01:59:25

问题


On my master page I have:

<form id="ReportForm" action="HelpAsk.aspx" method="post">
    <input type="hidden" id="HiddenReport" type="text" />
</form>

This is outside any server tags, just before the tag.

Jquery submits this form when a button on the page is clicked somewhere:

function SendReport() {
    $("#HiddenReport").val("<html>" + $("html").html() + "</html>");
    $('#ReportForm').submit();    
}

But whatever I try, I can't get my receiving page to read that data:

NameValueCollection nvc = Request.Form;
if (!string.IsNullOrEmpty(nvc["HiddenReport"]))
{
    Response.Write("LOL:" + Request.Form["HiddenReport"]);
}

回答1:


You need to give the input element a name attribute to have it posted with the form submit, e.g.

<input type="hidden" id="HiddenReport" name="HiddenReport" />

Also you have two type attributes, remove one of these.




回答2:


you need to add name attribute

<input type="hidden" id="HiddenReport" name="HidenReport" type="text" />

name use as key in posted form



来源:https://stackoverflow.com/questions/5646720/asp-net-c-sharp-cant-read-posted-form-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!