How to Pass value from text using @html.actionlink in asp.net mvc3 ?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With