Here is my code:
@{
ViewBag.Title = "My page";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
$(document).ready(function () {
$('#menucontainer').hide();
});
</script>
<h2>My page</h2>
@foreach (List<MyClass> item in (List<MyClass>[])ViewData["myList"])
{
foreach (MyClass item1 in item)
{
if (item1.name.Equals("something"))
{
<script type="text/javascript">
$(document).ready(function () {
$('#idSomething').show();
});
</script>
continue;
}
}
break;
}
I have a breakpoint in if, in the {. It gets hit and then it goes to continue;. The code in the script: $('#idSomething').show(); never gets hit! Why is this and how to solve this?
I also tried:
if (item1.name.Equals("something"))
{
@: ("#idSomething").show();
continue;
}
And again, the show() call breakpoint isn’t hit.
Javascript is clientside and therefore cannot be stepped through as C# code can be in the VS debugger.
To step through your javascript code there are several tools, most notably Firebug for Firefox. If you view your code in the javascript tab you can set breakpoints and step through/over/into as you would in Visual Studio.