ASP.Net Razor Syntax for using a variable in html or html attribute

Because I always forget how to do this, here’s a quick note on the Razor syntax in an html variable. For a integer variable named: imgWidth that has a value of 214 you can put it in an html attribute like this:

and it will render like this:

I know I know. The css gurus will be lambasting me that I put inline styles in this example. So sue me. Sometimes inline styles are necessary.

Continue reading

ASP.NET MVC Model binding in PHP?

I’ve been working a lot this year with ASP.NET MVC 3 and C#. One of the things I really like about these technologies is the model binding. Let’s say I have a data model called “User”, a plain old C# class like this:

I can set that as a model for my view to use in the “Edit” controller like so:

And then I have “User” as the data model in my view. Here’s what’s awesome about it, let’s say I need to accept edits of the user account, maybe they can fix their first or last name. I can pass that same User model from the previous page via a form into an Edit method that accepts that data model. I don’t have to muck about with assigning the Request variables ( POST / GET ) to an object. All that is handled for me.

The ASP.NET MVC model binding will attempt to bind your model in these scenarios:

  • If you have a form element on the page with an identical name to a property in the model
  • If the url contains a key value pair from your routing that is identical to a property in the model
  • If any REQUEST element has a name that is identical to a property in the model
  • Otherwise, that property of the model will remain null

Plus, the ASP.NET MVC model binding will let you turn on/off model binding for various properties of the model.

PHP, or rightly, the many PHP frameworks really need to implement something like this. A few perform some pieces of this concept but I’m not aware of any that currently serve up the whole enchilada. What do you think?

Continue reading

PRADO framework for PHP similar to ASP.NET

For Drew, the .NET fanboy who is just dying to release his app without having to shell out the big bucks for .NET hosting.  The PRADO framework for PHP is almost like ASP.NET.   From the homepage:

PRADO is a component-based and event-driven framework.

Look at that example on the homepage.  That’s .NET with a PHP5 wrapper on it, not literally of course, but you get the point.  And yes, it has user authentication built in as recently described in this PHP framework comparison chart.  Enjoy.  And I’ll take the first 1,000 shares at a discount when you go public.

Continue reading

Yes you, Mr. ASP.NET developer can use a hosted open source Subversion source control for your projects also

For some reason, most .NET devs that I run into insist on using closed source applications for everything they do. I have no idea why. I guess it’s a culture thing. That’s why I love it when a mostly ASP.NET fellow starts using something open source, like Subversion source code control. All the tools are in place to do what you need, the TortoiseSVN windows explorer plug-inthe Ankh Visual Studio plug-in. It’s all there.
Plus, I’ve really fallen in love with the concept of a hosted subversion solution. For me, I host my own at my provider. But for my side projects, its great to be able to access them from multiple computers. If I can get to the internet, I can get to my project code.

Continue reading