笑故挽风 2015-09-23 10:31 采纳率: 100%
浏览 4

如何推送Json并选择

I am trying to make post filter in my web site. There are checkboxes which will do filtration posts.

If checkbox is not checked there will not be that user's posts in page.

When page is loaded, checkboxes are not checked, so that I am trying to take some posts to Json format with checkbox id while page is loading.

If checkbox is checked, post will be visible.

I have tried that code part which is below.

I am getting null length error. could you help me? Is there a different way of doing this?

$(":checkbox").click(function () {

    if (this.checked) {

        $.each(inspostHtml.filters, function (i, v) { 
            if (parseInt(v.id) == parseInt($(this).attr('ID')) ) {                              
               alert(v.html); return; 
            }
        });
     } // end of if(this.checked)
     else {
          alert("Checkbox is unchecked.");
    }
    var _inspostHtml ={
                 "filters":[{
                        "id" : parseInt($("input:checkbox").attr('ID')), 
                          "html" :getMessageHtml(post.title, post.message, post.ID)}
                         ]};
    inspostHtml.push(_inspostHtml);

HTML

@for (int i = 0; i < Model.FilterType.Count; i++) 
{ 
   @Html.CheckBoxFor(m => m.FilterType[i].Checked, new { id = Model.FilterType[i].ID })
   @Html.HiddenFor(m => m.FilterType[i].Text) @Html.DisplayFor(m => m.FilterType[i].Text)<br /> 
}
  • 写回答

0条回答 默认 最新

    报告相同问题?