I have a complex Json data coming as a string being part of Model.
On Document ready I am parsing some JSON into a Javascript object with the help of following code:
JSON.parse($('#myData').val());
I am evaluating some condition in the JS function & getting a raw HTML string (something like : <h2><strong>Note :</strong> No Data found for the selection made</h2> )
I want to make the div visible & plugin this code in @Html.Raw() that is present in my HTML body after the above statement gets evaluated.
For example:
<div id="divNoDataFoundMessage" style="display: none">
<span class="" style="padding-right: 100px;">
@{
@Html.Raw()
}
</span>
</div>
Please help me how I can substitute the data from document.ready to the above code to display it dynamically.
<input type="hidden" value="@Model.MyListData" id="myData"/>
$(document).ready(function () {
var jsonData = JSON.parse($('#myData').val());
if (jsonData.NoDriversFound != "") {
$("#divNoDataFoundMessage").show();
$("#divNoDataFoundMessage span").text(jsonData.NoDriversFound);
}
};
$(document).ready()but also talking about server-side Razor markup like:@{ @Html.Raw() }I think your question might be made more clear if you tell us where the JSON data inmyDatais intended to come from. Looks like it is expected as soon as the page is ready.