如何在母版页的表单元素中添加隐藏字段
我想通过 jquery 或 javascript 将隐藏字段添加到我拥有的每个视图中。但我希望该代码位于 MasterPage.Master 中,因此我在一个地方编写代码,并将其添加到我拥有的每个视图中。如果可以的话我可以这样做吗?我使用 asp.net mvc 2
I want to add hidden field to every view i have through jquery or javascript. But i want that code to be in MasterPage.Master so i write code at one place and it adds on every view i have. Can i do this if yes then how? Im using asp.net mvc 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的母版中:
或者如果您希望将此隐藏字段插入到某个特定位置,请将
$('body')
替换为您在母版页中某处放置的占位符的其他选择器。您还可以通过给它们一些 id 或类来将其插入到现有的In your master:
or replace
$('body')
with some other selector to a placeholder you've put somewhere in your master page if you want this hidden field to be inserted in some specific position. You could also insert it into existing<form>
by giving them some id or class (if you have more of them on the same page and you wanted to insert this hidden field in each form).不确定 MVC,但在母版页
Page_PreRender
方法中,您可以有这样的代码:无论哪个页面使用母版页,这都会将隐藏字段推送到表单。
Not sure about MVC but in the master page
Page_PreRender
method you can have such code:This will push the hidden field to the form regardless of what page is using the master page.