javascript - ASP.NET MVC - Invalid assignment left-hand side when trying to use C# inside JS function -


i have view pass values session. achieve this, i've created js function called whenever click specific button. function receives index number parameter , retrieves relative object model passed view , own quantity selected option list in viewpage, assigning both session. problem i'm facing can't figure out how mix javascript , c# correctly. in current situation i'm receiving following error console:

referenceerror: invalid assignment left-hand side

which refers following html generated application:

 function setitemtosession(index) {          '0' = index;         var selectedvalue = document.getelementbyid(("quantityselection" + index)).nodevalue;         var itemselected = b2bcommercethesis.models.viewmodels.shoppingitem;         '' = itemselected;         '' = selectedvalue;           alert("everything works great index: " + index);         return;     } 

the relative code inside view is:

<script type="text/javascript">      function setitemtosession(index) {              @indexselected = index;             var selectedvalue = document.getelementbyid(("quantityselection" + index)).nodevalue;             var itemselected = @model.shoppingitems[indexselected];             '@session["shoppingcart"]' = itemselected;             '@session["itemquantities"]' = selectedvalue;               alert("everything works great index: " + index);             return;         }       </script> 

where indexselected global variabile defined @ begin of .cshtml.
know it's dumb question, can't find standard practice handles problem efficently. how can resolve this? thank in advance.

you trying change serverside session's in javascript on client, not possible.

if want change session need make mvc or webapi call or keep data in client's localstorage


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -