Examine HTML output when debugging MVC Views - asp.net-mvc

Is there a way to view what HTML has already been produced by an MVC Razor View when stepping through it with a debugger?
For example, in a view such as the following:
...
#Html.Raw(someString)
#Html.Partial("_SomeCommonComponent")
#Html.Raw(someOtherString) <---------- Execution broken at breakpoint here
...
Is it possible to see the combined output of just the first call to 'Raw' and the Partial view?
The reason I ask is that I have several complex calls together, (some which produce no output at all) and one of them is inserting incorrect characters, and I'd like to be able to find which call is the culprit by stepping over the code until the incorrect character has been output.

In Visual Studio you could put a break point on a code line in the view, then add a watch on both the Html.Raw(somestring) and Html.Partial("_SomeCommonComponent") method calls. You should then be able to see the HTML values in the watch window.
Also try and watch the ViewContext.Writer property in the view.

Related

Testing for an empty list in FitNesse .Net

FitNesse .Net (using the FIT test system, not SLIM) supports testing for lists of the form:
element1, element2, ..., elementN
This works well. However, I can't figure out how to test for an empty list.
Empty strings can be tested for with blank. What's the equivalent for a list?
Try this:
|configure|processor|add operator|parsequotedstring|
|check|myemptylist|""|
Please see here: https://github.com/imanushin/NetRunner/wiki/Collection-result
If there will be any collection on output NetRunner (and fitSharp) will write several red rows (e.g. test will fail).
For example, by using such functions I'm checking the error entries in the log: the expected entries count is empty list. However, any problematic row will be presented to me on the web page, which is very useful: I collects log results from the several files and story them in the test.

Telerik Grid (MVC) does not display returned JSON

I have a telerik MVC grid. After making some changes to the underlying code, the grid no longer shows the results returned from the server. I can see the correctly formatted JSON return from the server (using functionality from Web Developer Toolbar), but the grid never actually shows the data. However, it also doesn't generate an error. The loading icon just keeps spinning.
Does anyone have a suggestion on how to localize the problem? Thanks.
EDIT
Well, I managed to get a step further. Apparently something goes wrong in the "bindData"-function located in telerik.grid.js. More specifically in line 462:
460. var evaluate = column.display;
461. if (evaluate)
462. html.cat(evaluate(data[rowIndex]));
When trying to render the last column in the first row, evaluate is set to anonymous and somehow, this results in an "invisible" exception. The markup of this column is:
columns.Bound(c => c.DocumentId)
.ClientTemplate("<a href=\"" + Url.Content("/") +
"/document/<#= DocumentId #>\" target=\"_blank\"><#= Naam #></a>")
.Filterable(false)
.Title("Naam");
I don't understand why this would be a problem, as I use similar templates elsewhere without any problem.
EDIT
Ok, I got it. Apparently some exceptions will not be shown in the Firefox/Firebug console. However, Visual Studio together with IE do not have this problem. I finally discovered that indeed the field "Naam" was missing in the IEnumerable.
So something to take away here is never to trust the results from just one browser ;-)
I had a similar behaviour recently when I had changed the type that the grid was expecting.
Make sure that your ajax call is returning the correct IEnumerable that is specified in the grid markup.
You need to post code for the GridAction and markup if you want a more accurate answer.

Django admin/doc/views/ all blank or broken

I'm trying to use Django's built-in admin docs feature to make writing templates easier. Supposedly if you go to /admin/docs/views you should get documentation for every view in your application. I see a list, but none of the links work:
-) Any view listed that's related to my application just goes to a blank page with nothing but the name of the view as a header.
-) The views related to admin all give me Django 404 errors when I click on them, except those that are related to the docs itself. The docs-related links also give me blank pages. (i.e. clicking /admin/doc/filters gives a blank page with nothing but "django.contrib.admindocs.views.template_filter_index" as a title, but clicking /admin/auth/user gives me a Django 404 error
The 404 errors lead me to suspect my URLconf is wrong, but all I did was uncomment the built-in lines. The relevant sections read:
# Uncomment the admin/doc line below to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
And I have no idea what to make of the blank pages. Do I need to provide some extra meta information somewhere, like I know you need to provide the get_absolute_url on models for some of the admin features to work right?
Even if no one knows the answer, any documentation on the admin docs feature would be useful -- I've been Google all over (and searching StackOverflow) and this feature seems very little-documented.
Thanks!
You need to add 'django.contrib.admindocs' to your INSTALLED_APPS in settings.py. It should already be there and commented out. Though it would be nice if the comment in urls.py mentioned it ... Source.
I've never looked at the views admin doc pages before -- I've never had a need to. B4ut you're right, they seem to be -- lacking in potential features.
If you give your views functions docstrings (documentation), that content will appear on your "blank pages".
Most -- no, all -- of the admin sites views are actually decorated member methods of admin.sites.AdminSite. I looked around, and a view of mine which uses a decorator also suffers from the 404.
The view responsible for view details starts:
def view_detail(request, view):
if not utils.docutils_is_available:
return missing_docutils_page(request)
mod, func = urlresolvers.get_mod_func(view)
try:
view_func = getattr(import_module(mod), func)
except (ImportError, AttributeError):
raise Http404
title, body, metadata = utils.parse_docstring(view_func.__doc__)
...
You can see it tries to import the view to get info from it; if the view is actually a decorator (which probably used an internal function to wrap the real view), it won't be able to import it. eg, if you do from django.contrib.admin.sites import index in a django shell, you'll get an ImportError, whereas django.contrib.admin.site.index (note the singular site) is a:
<bound method AdminSite.index of <django.contrib.admin.sites.AdminSite object at 0x...>>
Further, that last line in my snippet seems to indicate that there's a capability for finer control over what shows up on those pages, if you care to figure out the template that util.parse_docstring uses.

Why can't I set a breakpoint in a ASP.NET view?

If I set a breakpoint in the compiled code (for instance in an action), I can then step through, and eventually am stepping through the generation of the View.
I've found this useful a couple of times, but it's tedious as you have to step through a lot of code to get there.
However, I can't set a breakpoint in view. I just receive the message 'This is not a valid location for a breakpoint' from VS2008. Why is this?
Right click on the code you want to break on and go to "Breakpoint -> Insert Breakpoint".
Why? Must have something to do with the face your not working with a pure code file and hitting the left sidebar doesn't know which block of code to use.
Another thing that comes to my mind is to use the debugger; keyword in the view, though I am not 100% sure it will work as in ASP.NET ajax site.
Click to the code where you want to debug and than press F9.
UpTheCreek,
Not really a 'nice' way to do it, however, you can insert some 'flip-flop' code in your view that CAN have a breakpoint placed in it and then step from there. This code doesn't neccessarily have to perfom a function (tho obviously, would be useful if it did).
anyway, you don't want the crumbs, so here's the (meal) deal:
<%
int rspId = 0;
string uniqPageId = Guid.NewGuid().ToString().Replace("-", "");
%>
then, simply place the breakpoint at the side of any of those variable definitions.
Not clean and definately a 'jfar' markdown candidate :-)

How do I call use_javascript after include_javascripts has been called?

In my layout, I'm calling include_javascripts() in my <head></head> section. Later on in my layout, I'm calling a component which makes use of use_javascript(), but, unfortunately, the javascript has been output, so this request falls on deaf ears.
I can think of a few approaches:
Put the call to `include_javascripts()` at the bottom.
At the moment I can't do this, because I'm using a CMS on top of symfony which uses a lot of inline javascript.
Override the include_javascript helper, or create a new one, which adds doesn't add anything, but adds it adds to a queue that a filter will take care of after rendering the page.
This is sort of like the common filter which was removed from 1.2. Obviously, they don't seem to like this approach.
Are there any other alternatives?
The use_javascript function simply adds the specified script to a collection, which is output by the include_javascripts function.
In order to have inline javascript in your code, you will need to use tags, since the use_javascript is pointless unless include_javascripts is called afterwards.
If you do not want to deal with filenames and such, you could always use sfConfig::get('sf_root_dir') . js/filename.js to grab your file.

Resources