asp.net mvc 重定向到操作并从用户输入传递参数 [英] asp.net mvc redirect to action and passing a parameter from user input

查看:63
本文介绍了asp.net mvc 重定向到操作并从用户输入传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有输入框和按钮的页面,当用户单击按钮时,我想重定向到一个控制器操作,该操作将输入框的值作为参数.

I have a page with a input box and a button, when the user clicks the button i want to redirect to a controller action that has as parameter the value of the input box.

<input id="CodProiect" type="text" />
<input id="Cauta" type="button" value="Cauta" onclick="window.location.href='@Url.Action("Cauta", "Componente", new { CodProiect = "param" })';"/>

如何从输入框中获取参数"?

How can i get the "param" from the input box ?

推荐答案

你可以只使用带有 GET 方法的表单

You could just use a form with a GET method

<form action="@Url.Action("Cauta", "Componente")" method="GET">
  <input id="CodProiect" name="CodProiect" type="text" />
  <input id="Cauta" type="submit" value="Cauta" />
</form>

表单会将参数添加为 URL 的查询字符串的一部分,例如www.yoursite.com/Cauta/Componente?CodProiect=user+entered+value

The form will add the parameter as part of the query string of the URL e.g. www.yoursite.com/Cauta/Componente?CodProiect=user+entered+value

这篇关于asp.net mvc 重定向到操作并从用户输入传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆