Reputation: 1692
I want to call an ActionUrl with JavaScript. I have a few TextBoxes in my View. Like this:
View:
@Html.Label("Suchbegriff")
@Html.TextBox("GeneralSearchTextBox")
@Html.Label("Strasse")
@Html.TextBox("StreetTextBox")
And I have controller with a method like this:
Controller:
public ActionResult FindAdress(int id = 0, string street = "", string city = "", string plz = "", string name = "")
{
DoSomethingSpecialWithTheParameters;
}
My problem is, I want to pass the values from the TextBoxes into my FindAdress(...) Method, using JavaScript.
I started to build a JavaScript-Function like this:
View (Just the script-part):
function search()
{
window.navigate('@Url.Action("FindAdress", "Home",
new
{
id=3,
street = ?????
},
null)');
}
I dont know how I can access the TextBoxes from here. Any Ideas?
Thanks a lot.
Upvotes: 1
Views: 1063
Reputation: 81
$("#textBoxId").val():
Should be the answer to getting the textbox values. Am I missing something?
Upvotes: 0
Reputation:
Assuming you want to redirect to the FindAdress()
method
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
Upvotes: 1