最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - how to create a cookie in javascript and use in controller in mvc3 - Stack Overflow

programmeradmin1浏览0评论

Actually I am having a requirement like :

I need to get the ID's of checked records by using Javascript and store the id's in a cookie and access that cookie in controller and delete the records based on that id's

My Javascript is :

<script type="text/javascript">
    //<![CDATA[

    function SelectionChanged(s, e)
    {

        s.GetSelectedFieldValues("ID", GetSelectedFieldValuesCallback);
    }
    function GetSelectedFieldValuesCallback(values)
    {
        SelectedRows.BeginUpdate();
        try
        {
            SelectedRows.ClearItems();
            var s = '';
            for (var i = 0; i < values.length; i++) {
                //SelectedRows.AddItem(values[i]);
                s=s+values[i]+',';

            }
        }
        finally
        {
            document.cookie = s;
        }
        $("#count").html(gvRowSelection.GetSelectedRowCount());

    }
    // ]]>

Actually I am having a requirement like :

I need to get the ID's of checked records by using Javascript and store the id's in a cookie and access that cookie in controller and delete the records based on that id's

My Javascript is :

<script type="text/javascript">
    //<![CDATA[

    function SelectionChanged(s, e)
    {

        s.GetSelectedFieldValues("ID", GetSelectedFieldValuesCallback);
    }
    function GetSelectedFieldValuesCallback(values)
    {
        SelectedRows.BeginUpdate();
        try
        {
            SelectedRows.ClearItems();
            var s = '';
            for (var i = 0; i < values.length; i++) {
                //SelectedRows.AddItem(values[i]);
                s=s+values[i]+',';

            }
        }
        finally
        {
            document.cookie = s;
        }
        $("#count").html(gvRowSelection.GetSelectedRowCount());

    }
    // ]]>

Share Improve this question asked Dec 14, 2012 at 4:20 user1859953user1859953 11 silver badge5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

I'm not exactly sure what your question is specifically, but if you're looking for a way to set cookies via Javascript, check out the jquery-cookie plugin. You'd access it in your controller just like you would any other cookie:

Javascript

$.cookie('mycookie', 'myvalue');

C#

Request.Cookies["mycookie"].Value;

I think Scott was rigth except that you need to Base64 decode the data then JSON decode the data.

JavaScript

$.jCookies({name:'user',value:{name:'brian',level:'awesome'}});

C#

Convert.FromBase64String(Page.Request.Cookies["user"].Value)

For more information look at the following Page: Here

发布评论

评论列表(0)

  1. 暂无评论