I'm using jquery to show and hide sections of a search page. I have a Html.Textbox and Html.CheckboxListFor that I show and hide base on form input (when the form is submitted it will show/hide the textbox if there is nothing entered in the textbox and same goes for the checkbox section, if not checkboxes are selected when the form is submitted the checkbox section is hidden when the page redisplays. I'm also using a jquery .click function to show/hide these search options as needed.
The code for the click functions:
$('b.Text').click(function () {
$('div.TSearch').slideDown(200);
$('div.KSearch').slideUp(200);
});
$('b.Keyword').click(function () {
$('div.KSearch').slideDown(200);
$('div.TSearch').slideUp(200);
$('#SearchString').val('');
});
$('b.Both').click(function () {
$('div.KSearch').slideDown(200);
$('div.TSearch').slideDown(200);
});
@using (Html.BeginForm())
{
<div>
<!-- For styling the check boxes & text for the keywords section -->
<style type="text/css">
label {
display: inline-block;
padding: 5px;
font-size:small;
}
input[type="submit"] {
margin-left: 0px;
}
</style>
@{ var htmlListInfo = new HtmlListInfo(HtmlTag.table, 5, null,
TextLayout.Default, TemplateIsUsed.No);
}
@Html.CheckBoxListFor(model => model.KeywordIDs,
model => model.Keywords,
model => model.KeywordId,
model => model.Name,
model => model.SelectedKeywords,
htmlListInfo
)
</div>
}
EDIT
ViewModel:
public class SearchCasefileViewModel
{
public Casefile Casefile;
public Keyword Keyword;
public IEnumerable<Casefile> Casefiles { get; set; }
public IEnumerable<Keyword> Keywords { get; set; }
public IList<Keyword> SelectedKeywords { get; set; }
public List<string> KeywordIDs { get; set; }
}
As you can see when you click on the Keyword it hides the text box and clears the text box. I've tried to implement the same for the checkboxes by using Model.SelectedKeywords.Clear() but that doesn't update the page view so the check boxes are still checked. Is there a similar call that I can use to clear the check boxes?