将参数传递给 MVC Ajax.ActionLink
如何将 TextBox 的值作为 ActionLink 的参数发送?
我需要使用 Html.TextBoxFor
<%= Html.TextBoxFor(m => m.SomeField)%>
<%= Ajax.ActionLink("Link Text", "MyAction", "MyController", new { foo = "I need here the content of the textBox, I mean the 'SomeField' value"}, new AjaxOptions{ UpdateTargetId = "updateTargetId"} )%>
控制器/操作如下所示:
public class MyController{
public ActionResult MyAction(string foo)
{
/* return your content */
}
}
使用 MVC 2.0
How can I send the value of the TextBox as a parameter of the ActionLink?
I need to use the Html.TextBoxFor
<%= Html.TextBoxFor(m => m.SomeField)%>
<%= Ajax.ActionLink("Link Text", "MyAction", "MyController", new { foo = "I need here the content of the textBox, I mean the 'SomeField' value"}, new AjaxOptions{ UpdateTargetId = "updateTargetId"} )%>
The Contoller/Actions looks like this:
public class MyController{
public ActionResult MyAction(string foo)
{
/* return your content */
}
}
Using MVC 2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将输入字段值(例如文本框)发送到服务器的语义上正确的方法是使用 html
现在,在控制器操作中,您将自动获取用户输入的
SomeField
输入:当然,您可以通过坚持使用
ActionLink
来尝试违反标记语义和 HTML 的工作方式,即使它是错误的。在这种情况下,您可以执行以下操作:然后在单独的 javascript 文件中使用 jQuery 以不显眼的方式 AJAX 化此链接:
The semantically correct way of sending input fields values (such as textboxes) to a server is by using an html
<form>
and not links:Now in your controller action you will automatically get the value of the
SomeField
input entered by the user:You could of course try to violate the markup semantics and the way HTML is supposed to work by insisting on using an
ActionLink
even if it is wrong. In this case here's what you could do:and then in a separate javascript file unobtrusively AJAXify this link using jQuery: