Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Pass textbox value using @html.actionlink in asp.net mvc 3

How to Pass value from text using @html.actionlink in asp.net mvc3 ?

like image 906
kiransh Avatar asked Jul 02 '12 11:07

kiransh


People also ask

How to pass textbox value in ActionLink in mvc?

to pass data from the client to the server you could use a html form: @using (Html. BeginForm(actionName,controllerName)) { <input type="text" name="myText"/> <input type="submit" value="Check your value!"> } Save this answer.

How Pass value from HTML to controller in MVC?

Pass value from view to controller using Parameter In MVC we can fetch data from view to controller using parameter. In MVC View we create html control to take input from the user. With the help of name element of html control we can access these data in controller.

What is HTML ActionLink ()?

ActionLink(HtmlHelper, String, String, String, String, String, String, Object, Object) Returns an anchor element (a element) for the specified link text, action, controller, protocol, host name, URL fragment, route values, and HTML attributes.


1 Answers

None of the answers here really work. The accepted answer doesn't refresh the page as a normal action link would; the rest simply don't work at all or want you to abandon your question as stated and quit using ActionLink.

MVC3/4

You can use the htmlAttributes of the ActionLink method to do what you want:

Html.ActionLink("My Link Title", "MyAction", "MyController", null, new { onclick = "this.href += '&myRouteValueName=' + document.getElementById('myHtmlInputElementId').value;" })

MVC5

The following error has been reported, but I have not verified it:

A potentially dangerous Request.Path value was detected

like image 140
toddmo Avatar answered Oct 06 '22 01:10

toddmo