简体   繁体   中英

asp.net — store checkbox information for session

I have a list of items, that a user can check:

@for (int i = 0; i < items[].Length - 1; i++)
{
    <div>
        <a href="#" class="items-link">Selected Items</a>
        <span>
            <input type="checkbox" data="@item" class="items-checkbox" />
        </span>
    </div>
}

When a user checks an item, the link url is updated to include that item via javascript:

var url = "/checked-items/?";

for (var i = 0; i < itemsThatAreChecked.length; i++) {
    url += "item=" + itemsThatAreChecked[i] + (i == itemsThatAreChecked.length - 1 ? "" : "&");
}

$(".items-link").attr("href", url);

However, I would like to expand this functionality so that the items that a user has selected are available throughout their session. Would ViewBag be the appropriate choice for storing this information? Can the information be updated via javascript (ie when the item is checked, add it to the list, and when it is unchecked, remove it from the list)

您需要做的就是在用户单击列表中的一个项目以更新itemsThatAreChecked []时调用一个函数,然后在他们单击“提交”时,另一个JS函数可以使用被检查的项目构建URL。

尝试使用TempData代替ViewBag。

您需要做的是在用户单击列表中的一个项目以更新itemsThatAreChecked []时调用一个函数,然后在他们单击“提交”时,另一个JS函数可以使用被检查的项目构建URL。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM