One feature that is not widely known is the ability to edit your MVC Project file and turn on the ability to build MVC views at compilation time. This really helps with debugging, and this works nicely if you have a small project. But if you have a large project builds can drag on forever. So, one thing I would like is a ‘build views’ command so I can build as necessary.
Recently while searching for a way to do runtime Razor parsing I found the RazorEngine at http://razorengine.codeplex.com/. It’s pretty simple – it allows you parse Razor syntax template strings on the fly and render them. However, support for using with MVC View is fairly limited. However, with a bit of simple creativity you can get a long way.
Here is a code sample:
Here are the main points:
- The RazorEngine is accessed by calling the “Razor” static class as seen on line 9.
- The string template is created in line 3.
- To get output, we pass a string template, plus a model, to “Razor.Parse” which produces the output.
- In this case we are passing an anonymous object with a property “Action”, which is the Func delegate on starting on line 5.
The reason we’re passing a delegate here to call the Html.Action method instead of passing the Html object itself is that we cannot get extensions method support easily with the RazorEngine parser.
- When parsed and executed, the template calls the Action delegate that is on the Model object available to it. This call then executes Html.Action and returns the string output, which is then in-lined with the remainder of the template.
The results are simple:
Template Action: (Render: 56844b67-a1ea-4184-9daf-79036778467a)
Everything after “Template Action:” comes from the child action which is parsed from the string template and executed .
My ultimate goal would be to do runtime parsing that has the same affect as using the ShortCodes api in WordPress.
More to follow.
It’s good to have an open discussion on how HTML 5 is really an incomplete moving target … and Microsoft’s plans for that.
IE 9 Beta Has No Love for Data Developers
I am in general concerned about the what directions in Html 5 Microsoft has not taken in IE 9. Those it has, I am really enjoying. If you want to see how IE 9 beta scores on a basic HTML 5 readiness tool, kit here: http://html5test.com/.
At heart I am a data guy, and that means I have a strong interest in files and forms. And here is where IE 9 comes up short in regard to HTML 5. Let’s look at the highlights of what’s missing as reported by taking your IE 9 beta the link above.
- No new input types, attributes, elements or validation.
Want out-of-the-box multiple file upload or date picker? Thus far – your out of luck. And there is a lot more missing than that.
- No File API.
Not heard of this? This allows your to declare an element on the page as a drop source for files and allows you to send the files to the server via ajax. Mozilla and WebKit have this.
- No IndexedDB
Microsoft and Mozilla have successfully championed that JSON-based data storage service instead of Web SQL, but it is curiously absent from the beta.
There are others, but these are most vital for data developers. Microsoft, if you really want to make IE 9 be a win for data developers you need to implement these in this version of the product even if you have to delay the product a few months. Even if that means trying to work thru the W3C to get these finalized early, and/or partial implementation.
Given the rate of adoption of IE, the frequency of releases by Microsoft, and that adoption will be initially slowed due to a lack of XP support, it would be easily 3 years from now before we can consider broad support for these features to be available if they are included in this version. If these features have to wait for IE 10 then I am afraid it will be too late.
If you are a data developer and agree, let Microsoft know your concerns have not been addressed. I have said nothing until now, because I foolishly assumed they would show up in the beta. I was wrong.
BTW – please consider adding the Web Feed notification icon back to the icons list next to the home button. A LOT of people have been to look for the icon in their browser, and may panic when it gone. I have over 150 feeds I read with IE, and I panicked when I couldn’t find it.
I am a web developer and use IE 9 beta as my primary browser at home.