从视图调用控制器,传递输入文本字段
我有两个文本输入,当单击按钮时,需要将其内容作为参数传递给某个操作。我正在使用MVC3 视图:
<input name="input2" type="text" class="inputfield" id="datepicker_1" /></td>
<input name="input2" type="text" class="inputfield" id="datepicker_2" /></td>
@Html.Action("Search", ...)
控制器: 公共 ActionResult 搜索(...) 我想为此应该在@Html.Action 中使用对象routeValues 或RouteValueDictionary。这些对象让我有点困惑。有人可以帮我澄清一下吗?谢谢你!
I have two text inputs, content of which needs to be passed to a certain action as parameters when a button is clicked. I'm using MVC3
View:
<input name="input2" type="text" class="inputfield" id="datepicker_1" /></td>
<input name="input2" type="text" class="inputfield" id="datepicker_2" /></td>
@Html.Action("Search", ...)
Controller:
public ActionResult Search(...)
I suppose the object routeValues or RouteValueDictionary should be used in the @Html.Action for this. These object are confusing for me a bit. Could anyone clarify this for me please. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Html.Action 可能会在您提供输入之前生成链接 html。您需要将输入放在要提交给您的操作的表单中,或者使用 ajax(可能带有 jquery)来调用该操作,如下所示:
对于 Ajax 示例,请检查此问题:
适用于 ASP.NET MVC 3 的 jquery ajax 表单
希望这会有所帮助...
The Html.Action will probably generate the link html before you provide the inputs. You need to either place your inputs inside a form to be submited to your action, or use ajax, with jquery perhaps, to call the action, like so:
For an Ajax example, check this question:
jquery ajax forms for ASP.NET MVC 3
Hope this helps...
似乎您需要在视图上进行提交,然后在控制器上实施后操作来处理提交。即视图中的某些内容
,
参数取决于您的视图是否是强类型的。以上假设不是。
It seems like you need have a submit on your view, and then implement a post action on your controller, to handle the submit. I.e. something along the lines of
in the view, and
the parameters depend on whether your view is strongly typed. The above assumes its not.