Wie man klar session mit jquery?

Ich bin der Entwicklung von mvc-Anwendung. Ich benutzte session in view und controller.
Erste wenn ich die Option Wert aus dropdown-Liste. ausgewählten Wert gesteuert wird, view und controller.
aber wenn ich wieder wählen, Wert aus dropdown-Liste), dass die Zeit auf change-Ereignis möchte ich klar-Sitzung.

unten ist mein code für die Ansicht

@model IEnumerable<StockWatch.DTO.ProductDTO>

@using GridMvc.Html
@using System.Web.UI.WebControls;

@{
    ViewBag.Title = "Index";
    int VendorId = Convert.ToInt32(Session["vendorId"]);
}

<!DOCTYPE html>

<html>
    <head>
         <link href="@Url.Content("~/Content/Custom1.css")" rel="stylesheet" type="text/css" />    
   </head>
<body> 

     @if (Model == null)
     {

    <div id="vendorDropdownDiv" class =" row-fluid Span9" style ="margin-bottom :15px">

                   <div class="span6"  >
                           <div class="span4" style="margin-left:35px;" >
                         <label >Vendor</label>
                    </div>
                    <div class="span6" >
                      @Html.DropDownList("VendorId", ViewData["list"] as SelectList, "-- Select vendor --", new { @id = "vendorDropdown", @name = "VendorId" })

                  </div>
                 </div>                              

                 <div class="span11" style="text-align:right">           
                <input class="btn btn-primary" type="submit" value="Create" id="create"/>
                 <input class="btn btn-default" value="Cancel" style="width:45px;" onclick="window.location.href='@Url.Action("index")    '"/>
           </div>
              </div> 
     }    

  <div id="indexview"></div>

     @if (Model != null)
     {
    <div id="modeldiv" class="span12" style="margin-left:0px;margin-right:0px;">
       <div class="row-fluid" style="margin-top:30px;margin-bottom:10px;">
       <div class="listheading span9" style="font-size:22px;">Products</div>

      <div class="createlink span3" style="text-align:right;margin-left:10px;">
       @Html.ActionLink("+ Add Product", "Create")
    </div>
  }     
</body>
</html>

<script>
    $(document).ready(function () {      
        $('#vendorDropdown').change(function () {                  
        }); 
    });
</script>

- und controller-code, wie unten

       public ActionResult Index(int VendorId=0)
    {
        if (VendorId == 0)
        {
            VendorId = Convert.ToInt32(Session["vendorId"]);
        }

        VendorService vendorService = new VendorService();
        SelectList SelectList = new SelectList(vendorService.GetAll().OrderBy(t => t.Name), "Id", "Name", VendorId);
        ViewData["list"] = SelectList;

        var Categorylist = new SelectList(new[] { "Dull", "Anodised", "All" });

        ViewData["Categorylist"] = Categorylist;

        if (VendorId != 0 )
        {
            Session["vendorId"] = VendorId;
            ProductService productService = new ProductService();
            var productlist = new List<ProductDTO>();             
            productlist = productService.GetAll().Where(x => x.VendorId == VendorId).ToList();

            return View(productlist );
        }
        else
        {
            return View();
        }
    }

hier, wie klar Convert.ToInt32(Session["vendorId"]); dieser Sitzung mithilfe von jquery.
thank u im Voraus

  • Erstellen Sie eine Aktion ClearSession und rufen Sie es mit $.ajax oder $.get.
  • Sitzungen verwaltet server und konnte nicht entfernt werden auf den client, ohne E-Anfrage an den server. Sie können einen ajax-Aufruf und es tun.
  • Sie können versuchen, diese: stackoverflow.com/questions/19470517/...
InformationsquelleAutor sanjivani | 2014-07-02
Schreibe einen Kommentar