I have created a Html helper for searching text given by the user using Razor helper inline.
The code i have written is as follows;
<script type="text/javascript">
$('#companyName').change(function () {
var searchTerm = $(this).val();
@Search(searchTerm);
});
</script>
<p>Search For:</p>
@Html.TextBox("companyName", Model)
@helper Search(string searchTerm)
{
if (searchTerm !="" || searchTerm != null)
{
@searchTerm;
}
else
{
@searchTerm.Substring(0, 7)<text>...</text>
}
}
Here i want to pass the value of textbox to the searchTerm. How can I do that..?
Razor helpers execute at the server. In your case you are subscribing to the
.change()event of thetextboxon the client. So you need to write a client side javascript handler, not a Razor helper: