1

I have the following snippet in my razor view.

@Html.ActionLink("US", "List", "Campaigns", new { country = "US", vertical = "Insurance" }, null)
<input id="verticals" />

How do I substitute vertical = "Insurance" with the value of <input id="verticals" />?

Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121

2 Answers2

2

This depends on the source of the value that is in the input with id="verticals". if the value is coming from the server, then you'd use that. If you would like to apply value that is, for example typed in the input (in case the input type="text"), then you'd have to use some JQuery to update the link with the typed varaible. Example in this case:

$('#verticals').change(function(){
    $('#IdOfTheLinkTag').attr('vertical',$(this).val());
});

The code is not tested, but you get the idea.

Dmitry Efimenko
  • 10,973
  • 7
  • 62
  • 79
0

I don't think this is possible. If you want that do it with JS and build the link yourself.

<a href="#" onclick="javascript:ClickMe();">Click me!</a>
<input type="text" id="verticals">

<script>
var vert = $('#verticals').val;
$.post() //bla bla
</script>

this is just some pseudo code but you get the idea. i hope :)

*Note: If verticals is an hidden field from the controller / model it easier of course

@Html.ActionLink("US", "List", "Campaigns", new { country = "US", vertical = Model.HiddenProperty}, null)
Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37