I wrote System.Console.WriteLine("How can I see this debugging information in a browser");
in the model of my ASP.NET MVC4 project. How can I see this debugging string in the browser console, or at least in Visual Studio?. I can't find it in the output window of Visual Studio. Maybe I need to install some plugin from NuGet?
Press F11 . Visual Studio calls the Console.
Console. Writeline() shows up in the debug output (Debug => Windows => Output).
In Visual Studio 2010, on the menu bar, click Debug -> Windows -> Output. Now, at the bottom of the screen docked next to your error list, there should be an output tab. Click it and double check it's showing output from the debug stream on the dropdown list.
Console.WriteLine(...)
will not be displayed. If you absolutely need to see output in the debugger, you'll have to use
System.Diagnostics.Debug.WriteLine("This will be displayed in output window");
and view it in the Output window. You can open the output window by going to Debug -> Window -> Output
:
Here's an example of what this will all look like:
For further readings, check out this SO post.
You can write to your Javascript console from your C# Code using the following class
using System.Web;
public static class Javascript
{
static string scriptTag = "<script type=\"\" language=\"\">{0}</script>";
public static void ConsoleLog(string message)
{
string function = "console.log('{0}');";
string log = string.Format(GenerateCodeFromFunction(function), message);
HttpContext.Current.Response.Write(log);
}
public static void Alert(string message)
{
string function = "alert('{0}');";
string log = string.Format(GenerateCodeFromFunction(function), message);
HttpContext.Current.Response.Write(log);
}
static string GenerateCodeFromFunction(string function)
{
return string.Format(scriptTag, function);
}
}
Works just like its JS version, it actually converts your message to JS and injects it into the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With