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
Post a Comment