是否有一些我可以在提交按钮上设置的属性,以使其同时用于单击和使用回车键?
这是我的HTML
<div>Search:</div> <form action="/Item/Search" method="post"> <input ID="FTSearchText" name="FTSearchText" type="text" value="" /> <input type="submit" value="Go" name="FTSearchbutton" /> </form></div>
在服务器端,我有一个自定义模型绑定器,它使用以下代码来确定用户是否单击了提交按钮.
//See if the value provIDer has the required prefix var hasPrefix = bindingContext.ValueProvIDer.Containsprefix(bindingContext.Modelname); var searchPrefix = (hasPrefix) ? bindingContext.Modelname + "." : string.Empty; var searchbutton = GetValue(bindingContext,searchPrefix,"FTSearchbutton"); //If this value doesn't have value,the user dIDn't click the button so exit if (string.IsNullOrEmpty(searchbutton)) { return null; } private static string GetValue(ModelBindingContext context,string prefix,string key) { var result = context.ValueProvIDer.GetValue(prefix + key); return result == null ? null : result.AttemptedValue; }
编辑
所以,这就是我遇到的问题.我有一个显示项目列表的页面.我有一个’搜索’文本框和一个HTML格式的提交按钮.当用户在文本框中输入文本并单击搜索按钮或使用回车键时,页面通过http get发布表单数据,并返回找到的前8个记录.然后页面显示其他页面的页面链接.问题是,当用户单击页面链接时,表单数据全部为空白,并且我的过滤器信息丢失(使用这些链接时,表单不会使用表单值发布).因此,我最终显示一个空白的项目列表(空白搜索返回0结果),而不是分页数据.
通过在表单数据中添加对按钮名称的检查,我可以确定是否只是简单地分页数据,或者进行新的查找.
我希望这是有道理的.
解决方法 我不会依赖这个.这种情况有很多记录的错误.为什么不添加name =’submit’的隐藏字段?这样重新编码后端就不会太难了.<input type='hIDden' name='submit' value='FTSearchbutton'/>总结
以上是内存溢出为你收集整理的使用回车键时,Html表单不包含表单提交按钮名称全部内容,希望文章能够帮你解决使用回车键时,Html表单不包含表单提交按钮名称所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)