如何重新加载会话值

时间:2018-06-04 10:29:50

标签: asp.net-mvc asp.net-ajax

我使用ajax,modelID,catId等从视图向控制器发送数据,并根据这些参数从数据库中搜索数据,但是第一次加载会话值但在此之后如果我更改其值不能加载会话值。

  $("#ModelID").change(function () {
        var Cat = $("#Cat").val();
        var subcat = $("#CatID").val();

        if (Cat != "" & subcat != "") {

            $("#modalvalag").modal("show");

            $.ajax({
                type: 'post',
                url: '/Inventory/CatSubCatAgainstModal',
                data: {

                    Cat: $("#Cat").val(),
                    SubCat: $("#CatID").val(),
                    ModelID: $("#ModelID").val()
                },

                success: function (response) {

                    $('#noo').html(response);
                }

            });
        }
        else {
            alert("Please select Category Or sub category to complete this process");
        }

        return false
    });

这是控制器代码:

public ActionResult CatSubCatAgainstModal(int Cat = 0, int SubCat = 0 , int ModelID = 0)
    {
       // var dta = db.ItemsCatSubCats.Where(m => m.CatID == CatID & m.SubCatID == SubCatID).FirstOrDefault();
        //Session["ItemName"] = dta.Category.Catgory + "|" + dta.SubCategory.SubCat;
        Session["CatID"] = Cat;
        Session["SubCat"] = SubCat;
        Session["ModelID"] = ModelID;
        var data = db.ItemAttributes.Where(m => m.CatID == Cat & m.SubCatID == SubCat & m.ModelID == ModelID).ToList();
        int c = 0;
        foreach(var itm  in data){
            Session["value"+c] = itm.AttributeValue;
            c++;
        }
        return RedirectToAction("AttributListForValue");
    }

0 个答案:

没有答案