javascript - script inside Razor, unable to correct using @: -


i compile error @ $(this).id)

<script>             if ('@content.tolist().count' > 0)              {                 $(".divcontainer").text('@content.where(p => p.containerid == `$(this).id`).select(p => p.textcontents).first()');             }             else              {                 $(".divcontainer").text("please enter text");              } </script> 

how add id of 'this div' class 'divcontainer' inside razor code @content.where(p => p.containerid == "id".select(p => p.textcontents).first()

question made simpler.

how write following code correctly

@string text = $(this).text(); 

here razor variable 'text' assigned jquery text value.

use .attr() method of jquery id

 if ('@content.tolist().count' > 0)      {         $(".divcontainer").text('@content.where(p => p.containerid == $(this).attr("id")).select(p => p.textcontents).first()');     }     else      {         $(".divcontainer").text("please enter text");      } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -