Reputation: 784
I have following view side code in cshtml
<div class="item-grid">
@foreach (var product in Model.Products)
{
var itemboxid = "item-box_" + @product.Id;
<div class="item-box" style="display:none;" id="@itemboxid">
@Html.Partial("_ProductBox_Category", product)
</div>
}
</div>
by defalt the content is hidden.i am trying to unhide the content using following javascript
$(document).ready(function () {
$("#search-box-button").click(function () {
var city = $('#city').val();
var serchterm = $('#small-searchterms1').val();
@foreach(var product in Model.Products)
{
@:if([email protected])
{
var pro_id = "#item-box_" + product.Id;
@:$("@pro_id").show();
}
}
});
});
#city
is the id value of the textbox where we can enter the text data
but this code is not working fine please help me to solve this problem
Upvotes: 0
Views: 68
Reputation: 58462
I usually use <text>
tags (and have fixed your prod id at the end - it looks you were getting your js and razor variables mixed up):
$(document).ready(function() {
$("#search-box-button").click(function() {
var city = $('#city').val();
var serchterm = $('#small-searchterms1').val();
@foreach(var product in Model.Products) {
<text>
if (city == '@product.city') {
var pro_id = "#[email protected]";
$(pro_id).show();
}
</text>
}
});
});
Upvotes: 1