ASP.NET MVC inline Razor variable - asp.net-mvc

In pre-Razor MVC I could write this in a view:
<span>I want to write in<%= myVariable %>side</span>
In Razor, of course I can't
<span>I want to write in#myVariableside</span>
bacause the template engine would look for the variable #myVariableside. How to solve this? Thanks

First - have you tried it?
Secondly - if the interpreter has issues - you can try #(myVariableside).
Equally if the variable name you're talking about is #name - then once you're inside the parentheses everything's fine, because the interpreter knows it's parsing C#/VB: #(#myVariableside)

You can use <span>I want to write in#(myVariable)side</span>
Edit: Aww.. should have known better than to answer this question ^^

Do it this way
<span>I want to write in#{ #myVariable }side</span>

Related

How to add variable in middleman html

I have some .yml files that may be dynamic. So I wanted to add this kind of code on my html:
<h3><%=data.fitness_programs["#{f.filename}"].en.title%></h3>
Looks line the rails "#{var_in_here}" is not possible here.
How can I do this?
My bad, as this was a loop of filenames I did not realize I had an error in one of these. The code above does work :)

Cannot use Zend_Debug::dump in ZF2..how do I?

I'm using the skeleton application for ZF2.0.0Beta3.
So, normally I would just use Zend_Debug::dump($someVar); however, in ZF2 it doesn't include the zend classes it seems.
The error is: Fatal Error: Class 'Zend_Debug' not found..
This is probably a really basic question, but what's the best way to include that class? Do I have to put require_once('path/to/Debug.php');?
It still exists in ZF2, but since ZF2 started using PHP namespaces, you would now have to call it using the Zend namespace:
\Zend\Debug\Debug::dump($var);
or add a use statement at the beginning of the file and call it like this:
use Zend\Debug\Debug;
Debug::dump($var);
In my case this was the correct namespace-path :
\Zend\Debug\Debug::dump($form);
Additionally, you can get it like this:
use Zend\Debug\Debug;
// ...
Debug::dump($someVar);
Seems like a lot of work just to dump a variable, though. I'm pretty sure in most case I'll just end up using \Zend\Debug\Debug::dump() more often.
You can use it like that:
\Zend\Debug::dump('asd')

Lint for ASP.NET MVC?

Is there a lint utility for ASP.NET MVC? Given that I frequently specify views and links via strings, when I move things around or change entity names I often break things, which I then only find out about when something fails at runtime.
ReSharper's v6 (whose nightlies are now available, if you don't mind living on the edge) will catch this kind of error for you.
You can use Refactor -> Rename and enable Search in Strings to replace every string in the solution
Other option -- use the strongly typed helpers (which might still be in the futures assemblies). EG, Html.Action<ProductsController>(x => x.ShowProduct(id)) ; really the only way to fly.
I don't know that there's something like that, but I'll tell you what I do: All my view names are in a struct that contains string constants. It's a pain to keep it sync'ed as the project changes, but it's worth it because you're far more likely to catch errors if you're using
ViewNames.Customer
rather than
"customer"

MVC #import html keyword

I'm trying to use:
<style>#import url("css/main.css");</style>
but mvc treats it as .net code in razor view. "CS0103: The name 'import' does not exist in the current context"
how do i fix it?
thanks
Double the # to fix the issue:
<style>##import url("css/main.css");</style>
More details here.
Use two ## characters to escape them, that should fix it.

Problems with Netbeans re: Rails erb/rhtml intellisense?

I've been using Netbeans for Rails and like it a lot, considering how little I paid for it. But something that bothers me is that when I'm editing an RHTML or ERB file, it doesn't do the code autocomplete - or at least not reliably. Sometimes it shows the appropriate variables and methods that are available on an object after you type the dot operator. Sometimes it ignores the instance variables. Is there a solution for this? (Please don't say RadRails).
Oh and one more thing in case anyone has solved this: considering how often I have to type <% when I'm in a Rails template, I wish there was some hotkey for autotyping the tag . . . ? I always have to stop and look down at my keyboard to find the < and % keys before I can type the tag so it's not as trivial as it might sound.
I believe you're looking for something like this:
http://ruby.netbeans.org/codetemplates-rhtml.html
Type in one of the triggers, then hit the tab key to expand it to the code as given.
Also, you might want to explore using HAML. It's much easier on the hands.

Resources