Asp.net MVC 将文本框值添加到路由链接

发布于 2024-08-23 19:55:29 字数 346 浏览 4 评论 0原文

我正在尝试学习 asp.net MVC,但在向模型提交文本框值时遇到问题。

我有一个文本框,用户将在其中键入一个数字,当他们点击路线链接时,路线链接将从文本框中获取值并将其分配给 .Page 项目之一。

<%=Html.TextBox("PageIndex")%>
<%=Html.RouteLink("Search", "UpcomingEvent", 
    New With {.Page = "I want to put value of PageIndex textbox here"})%>

如何将文本框的值分配给 .Page 变量? 感谢您的时间和帮助!

I am trying to learn asp.net MVC and having an issue to submit a textbox value to a model.

I have a text box in which users will type a number and when they hit the routelink the routelink will take the value from the textbox and assigns it to one of .Page item.

<%=Html.TextBox("PageIndex")%>
<%=Html.RouteLink("Search", "UpcomingEvent", 
    New With {.Page = "I want to put value of PageIndex textbox here"})%>

How can I assign the value of the textbox to .Page variable?
Thanks for your time and help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满栀 2024-08-30 19:55:29

您不能这样做,因为 RouteLink 是在服务器上呈现的。

如果您想根据用户输入构造一个 URL 而无需回发,则需要执行一些客户端脚本(即 JavaScript)。

You can't do that because the RouteLink gets rendered on the server.

If you want to construct a URL based on the user input without a postback, you'll need to do some client-side scripting (ie JavaScript).

陌上芳菲 2024-08-30 19:55:29

听起来您不希望在输入文本框值后回发到服务器。如果是这种情况,那么您将需要使用 javascript 来更改链接的 href 属性。 Html.RouteLink 全部在服务器端完成。

如果您使用的是jquery,那么它会像“

$("#pageIndex").change(function()
  {
    $("#pageLink").href += "?pageIndex=" + $("#pageIndex")"
  }

当然,这不适用于被触发的多个更改事件”,但这部分留给读者作为练习。

It sounds like you're not expecting to post back to the server once they have the textbox value entered. If that is the case then you're going to need to use javascript to change the link's href property. Html.RouteLink is all done server side.

If you are using jquery then it would be something like

$("#pageIndex").change(function()
  {
    $("#pageLink").href += "?pageIndex=" + $("#pageIndex")"
  }

Of course that isn't going to work with multiple change events being fired but that part is left as an exercise for the reader.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文