简体   繁体   中英

Error while using TempData values in DropDown

I have <div> and I want to add some TempData values to it. I have accessed that values but facing error on browser's console when try to assign to dropdown.

code :

@{
     var j = TempData["Contents"]; // int
     var i = TempData["ID"];   // string

      }
    var newSelect = document.createElement('select');
    var selectHTML = "";
    selectHTML = "<option id='"+@i+"'>'"+@j+"'</option>";
    newSelect.innerHTML = selectHTML;
    document.getElementById('surah_selection').appendChild(newSelect);
    alert("out");

How to fix it ?

razor render this script before it execute in browser, so in your case in runtime you have string

selectHTML = "<option id='"+ali+"'>'"+alj+"'</option>";

so browser try execute value for this variables, for solve this you need change this line something like this

selectHTML = "<option id='@i'>@j</option>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM