我想用 JavaScript 调用 ActionUrl。我的 View 中有一些文本框。像这样:
查看:
@Html.Label("Suchbegriff")
@Html.TextBox("GeneralSearchTextBox")
@Html.Label("Strasse")
@Html.TextBox("StreetTextBox")
我有一个带有如下方法的 Controller :
Controller :
public ActionResult FindAdress(int id = 0, string street = "", string city = "", string plz = "", string name = "")
{
DoSomethingSpecialWithTheParameters;
}
我的问题是,我想使用 JavaScript 将文本框中的值传递到我的 FindAdress(...) 方法中。
我开始构建这样的 JavaScript 函数:
查看(仅脚本部分):
function search()
{
window.navigate('@Url.Action("FindAdress", "Home",
new
{
id=3,
street = ?????
},
null)');
}
我不知道如何从这里访问文本框。 有什么想法吗?
非常感谢。
最佳答案
假设您想重定向到 FindAdress()
方法
function search() {
var street = document.getElementById("StreetTextBox").value;
var id = ....
var city = ....
// other values
var url = '@Url.Action("FindAdress", "Home")';
document.location.href = url + '?id=' + id + '&street=' + street + '&city=' + city; // plus other values
关于javascript - 从 JavaScript 中获取 cshtml 中的 TextBox-Value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26094321/