如何从布局到子视图获取数据 [英] How to get the data from layout to child views

查看:72
本文介绍了如何从布局到子视图获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- 场景



我在布局页面中有一个自动完成的文本框。当在文本框中选择某些内容时,它会转到不同的页面。但是下一页的文本框变空了。



- 所以我做的是我包含了session.js插件并包含了这部分



  if ($ .session.get('  Store')!= null){
$(' #StoreSearch')。val($。session.get(' Store' ));
$ .session.set( Store' ');
}











 jquery 







<脚本类型= 文本/ JavaScript的 > 
$(document).ready(function(){

if($ .session.get('Store')!= null){
$('#StoreSearch' ).val($。session.get('Store'));
$ .session.set(Store,'');
}

$( #StoreSearch)。autocomplete({

source:function(request,response){
$ .ajax({
url:'@ Url.Action(GetAutoCompleteStoreDetails, Home)',
数据:{storeid:request.term},
mtype:POST,
dataType:json,
成功:函数(数据) {
if(data.length> 0){
response($。map(data,function(item){
return {
value:item.StoreID + + item.StoreName,
id:item.StoreID
};
}))

}
else {
回复({
值:'未找到结果'
});
}
},
错误:function(){
alert('Invalid Search');

}

})
},
minLength:1,
select:function(event,ui){
if(ui.item.value!='未找到结果'){
window.location.href ='@ Url.Action(GetStoreSearchDetails,DMSStatus)'+'?StoreID ='+ ui。 item.id

//$('#StoreSearch')。val(i.item.id);
$ .session.set(Store,ui.item.value);
// session [store] = ui.item.id;

}
else {

$('#StoreSearch')。val('');

}
}
});

})

< / script>







- 所以这很有效。当我导航到下一页时,文本框不为空。

- 但我在新页面中有部分视图部分。所以这不会去布局页面。所以我在局部视图中做的任何东西都应该清楚......但是它不清楚..



请建议我如何保持布局数据子视图

解决方案

.session.get(' Store')!= null){


' # StoreSearch')。val(


.session.get(' 商店'));

--scenario

I have a textbox in the layout page which is autocomplete. when something is selected in textbox it goes to different page. But the textbox becomes empty in next page.

-- So what I did I included the session.js plugin and included this part

if ($.session.get('Store') != null) {
                $('#StoreSearch').val($.session.get('Store'));
                $.session.set("Store", '');
            }






jquery




<script type="text/javascript">
        $(document).ready(function () {
      
            if ($.session.get('Store') != null) {
                $('#StoreSearch').val($.session.get('Store'));
                $.session.set("Store", '');
            }

            $("#StoreSearch").autocomplete({

                source: function (request, response) {
                    $.ajax({
                        url: '@Url.Action("GetAutoCompleteStoreDetails", "Home")',
                        data: { storeid: request.term },
                        mtype: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.length > 0) {
                                response($.map(data, function (item) {
                                    return {
                                        value: item.StoreID + " " + item.StoreName,
                                        id: item.StoreID
                                    };
                                }))

                            }
                            else {
                                response({
                                    value: 'No Results found'
                                });
                            }
                        },
                        error: function () {
                            alert('Invalid Search');
                          
                        }

                    })
                },
                minLength: 1,
                select: function (event, ui) {
                    if (ui.item.value != 'No Results found') {
                        window.location.href = '@Url.Action("GetStoreSearchDetails", "DMSStatus")' + '?StoreID=' + ui.item.id 

                        //$('#StoreSearch').val(ui.item.id);
                        $.session.set("Store",  ui.item.value);
                        //session["store"] = ui.item.id;

                    }
                    else {

                        $('#StoreSearch').val('');

                    }
                }
            });

        })

    </script>




-- So this worked. The text box was not empty when I navigated to next page.
--But I have partial view part in the new page. So this doesn't go to layout page. So anything I do in partial view then text box should clear...but it doesnot clear..

Kindly suggest me an idea "how to persist the layout data in child views"

解决方案

.session.get('Store') != null) {


('#StoreSearch').val(


.session.get('Store'));


这篇关于如何从布局到子视图获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆