Alternative to Html.Button<T>? - asp.net

I know the Html.Button has been moved to the Microsoft.Web.Mvc namespace, but I really miss the generic versions that used to exist in the early Previews.
All I want the Html.Button to do is to hit an action in my controller, but I'd rather not write the JavaScript in the onClickMethod argument.
In my previous project I just snagged the generic Html.Button code from a previous preview release, but that doesn't seem like the best approach as things progress. There were also Html.NavigateButton... where is that and why should I have to recreate it?
How is everybody else doing this?

The problem with the generic versions is that filters are allowed to change the actual name of the action away from the name of the method (like the [ActionName] attribute).

Yes, they really screwed up with Html.Button and Html.CheckBox in CTP5. I hope they return to the previous behaviour.

Related

Symfony2 - Do not render a view from controller like ZF setNoRender

Relatively new convert to Symfony2 from ZF1.
I have Googled and cannot seem to find the answer. Just wondering if there is a way to not render a view from a controller action in Symfony2.
In a ZF controller I could use:
$this->_helper->viewRenderer->setNoRender(true);
What is the equivalent in Symfony2?
In Symfony nothing is rendered for you automatically. If you need to render something, you have to do it explicitly. If you don't want to render, just don't do it :) Simply return a response:
return new Response();
Only job of a Symfony controller is to return a response. Rendering a template actually creates a response as well.
Wanted to give my Opinion:
Just because there is a possibility to render(ControllerMethod,{ params}) in a template doesn't mean you have to use it.
Doing so leads almost always to a shitty architecture, the turning point where projects start to be hard to debug, since you are mixing a VIEW (Presentation layer) with a CONTROLLER, that in turn renders another VIEW. You get the point.
Then when you have an error in the ControllerMethod, and instead you get a template error, not so nice isn't it ?
I vouch for strong architecture in software projects. This cheap solutions, like using this commodities, lead to the start of the bad. And I suggest to avoid it as much as you can unless there is no other possible way. And certainly there is!
That is the reason to use MVC. To separate Code from Presentation layer, start mixing both, and your architecture will leak.

Force case-sensitive routing in ASP.NET MVC

This question has been asked in a similar but not identical fashion (and not resolved to my satisfaction) previously on Stack Overflow and elsewhere.
Coming from a linux-world, I want to use ASP.NET MVC but avoid identical but differently-cased routes from resolving to the same page. I do not want to force all routes to be 100% lowercase.
e.g. I want /Home/Something to be a valid route and /Home/somethingElse to also be a valid route, but not /Home/something or /home/somethingelse, given two functions called Something and somethingElse in the HomeController.
I can't find any way of doing this from within the RegisterRoutes function, but maybe I'm missing something obvious? I can answer this easily enough by adding code to each Controller function, but I'm obviously trying to avoid doing that.
Optimally, the solution would involve catching all permutations of a particular route, then 301 redirecting any that do not exactly match the case of the controller's function.
I was unable to find any way of doing this after extensive searching. Basically, case-sensitivity and IIS/ASP.NET apparently do not go together.
We're now using a bit of a kludge to solve this. The code has been opensourced (MIT license) on github: NeoSmart Web Toolkit, in particular, this file containing the SEO redirect code.
Using it is easy enough: each GET method in the controller classes needs to add just this one line at the start:
Seo.SeoRedirect(this);
The SEO rewrite class automatically uses C# 5.0's Caller Info attributes to do the heavy lifting, making the code above strictly copy-and-paste.
Ideally, I would love to find a way to turn that line of code into an attribute. For instance, prefixing the controller methods with [CaseSensitive] would automatically have the same effect as writing in that line, but alas, I do not (yet) know how to do this.
I also can't find any way of figuring this out with the Routing class/structures. That's some opaque code!

Looking for LLVM-based language which allows to reload part of binary on-the-fly

Are the any GIL-less LLVM-based languages, targeted mainly for JIT-execution which allows to reload PART of the code on the fly?
Like re-compile 1 class, and reload it without stopping the whole program.
Anyone tryed that?
Any chance on doing that with clang (surely, with great deal of developers caution, restriction and manual state handling)?
I think that this is a dynamite idea, and a feature that I would love to have! Have you given any thought to how you would like to interface with the feature?
obj1 = Foo()
compiler.Recompile(Foo, '/some/path/myapp/newsrc/foo.blah');
obj2 = Foo()
// Would this be True?
type(obj1) == type(obj2)
I assume that you expect existing instances to remain unchanged by the recompile?
This seems like it would be easier with functions, as long as they kept the same prototype, but doing it with classes seems like it would get messy.
Also, what to do about threading?
Thread.start(wait 1; bar();); // bar is a function
compiler.Recompile(bar, '/some/path/myapp/newsrc/bar.blah');
Lets say that in our thread we start calling "bar" during the recompile. Does the call block until the recompile is done and then call the new function? Does the old function still exist until the compile is complete? What if we have a function pointer, after the recompile, where does it point? To the original function or to the new one?
Does anyone have any thoughts on how this could be implemented in a strait forward way?
Hmm, can't think of anything off the top of my head. The only major product I can think of is JRebel, but that's for Java.
Apparently, it does not exist yet.

How to do Actionscript trace and/or component flow log using debugger

An existing (though incomplete) FLEX3 project was given to us to finish (always a nightmare).
It is quite small but highly abstracted (contains well over 150 files to support only about 10 page views). I'm attempting to trace a single mouseclick event through this maze.
Is there a way to print out an actionscript trace and/or component flow using the debugger (or any other tool that anyone knows of)?
The flash.txt file appears worthless since it doesn't contain ActionScript calls and/or component flows.
Thanks
This will print your execution graph:
Trace.setLevel(Trace.METHODS, Trace.LISTENER);
Trace.setListener(handleMethods);
function handleMethods(fqcn:String, lineNumber:uint, methodName:String, methodArguments:String):void
{
trace(methodName);
}
Oof. Yeah, always.
The Profiler might give you useful information, but you need to pay for FlexBuilder Pro to get it, if you don't already have it. I'm not real handy with the Profiler, so I may be off base with that advice. It would be worth checking into, though, if you are already familiar with other profiling tools.
I would probably just start looking at every point that .addEventListener(MouseEvent.CLICK occurs in the code - and .addEventListener("click", just in case the previous developer chose not to use the constant, for some reason.
Obviously, that could show up a lot in 150 files, but that's how I would go about it.
I would also look at any custom events that could get into the mix. Because maybe the CLICK event is handled at some point and the handler dispatches a custom event. And maybe the handler for that custom event dispatches another custom event. Or dispatches a MouseEvent.CLICK event, etc.
Hope that helps. Good luck...
Check out
http://jpauclair.net/2010/02/10/mmcfg-treasure/
esp.
AS3Trace = 1|0
This one is also very useful for
debugging It trace every single call
to any function that is being called
in the SWF at runtime! It’s like
expending the StackTrace to the full
software run time.
And many more.

StyleCop vs ReSharper and general coding-style questions

Just found StyleCop, looks like something worth using for my projects. Then I found out you could use it with ReSharper (a tool I've also never used). So I downloaded ReSharper, as well as StyleCop for ReSharper. I'm just a bit confused about it, though:
With just StyleCop installed (no ReSharper), I get yelled at for referring directly to private variables in code-behind. It wants me to instead do this.variable. Alright, fine.
If I use just ReSharper, it tells me to remove all of the 'this' calls I just added. Which one is better?
If I use ReSharper + StyleCop for ReSharper, it now tells me to add 'this' to all private member references (just like StyleCop did all by itself). However, now it also wants me to add 'this' to all of the controls I'm referencing from the .aspx page (i.e., Label.Text = this.variable -> this.Label.Text = this.variable).
I'm so confused. What is the best standard to follow? Or am I just fine doing it the way I am now (Label.Text = variable)?
The key point is consistency. Your particular formatting with regard to this point comes down to personal preference.
Does the extra wordiness provide additional clarity as to which variable you're referencing or does it obscure the meaning by flooding the page with extra text?
This is a judgment call. They do enforce other rules that make sense; however, a large part of what they do is enforce consistency. As #Martin said, feel free to disable rules that don't make sense for your workflow.
Sorry when working on a team it all comes down to understanding the politics; after all, we work to get paid!
If the person that decided your next
pay raise uses StyleCop, then you
should always include the “this.”
likewise if the boss uses ReSharper
you should do what ReSharper says.
There are a lot more important wars to win this, e.g. 10,000 line classes, over sized method
If you are luckly enough to decide what tools (and coding standards) are used yourself, then I would just choose ReSharper and read the “clean code” book.
I think it's up to you which conventions you want to follow (it's a matter of personal preferences). At least in ReSharper, you can edit the rules to no longer show certain warnings/hints.

Resources