【问题标题】:Pass multiple html parameter with BeginForm使用 BeginForm 传递多个 html 参数
【发布时间】:2012-11-06 07:40:28
【问题描述】:

我需要在 BeginForm html 中发送带有值的参数。

例子:

@ using (Html.BeginForm ("Create", "IncomeDeclaration", new {declarationAmount = document.getElementById ("element"). value}))

这个值我无法从模型中得到,因为它在模型中找不到。 我已经尝试了几种方法,但没有任何效果。如果您可以更改 ViewBag 的内容,那就太好了。

感谢您的支持。

【问题讨论】:

    标签: asp.net-mvc forms parameters


    【解决方案1】:

    您不能将 Javascript (document.getElementById ("element")) 与 C# 表单声明混合和匹配。如果您想要与表单一起提交的值,您应该在表单声明中添加相关的表单元素。如果您不想要常规表单元素(例如文本框),您可以使用“隐藏”输入字段。如果你愿意,你可以dynamically populate the hidden field using javascript

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多