Razor/CSHTML - Any Benefit over what we have? [closed] - c#

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Anyone out there using the new CSHTML pages feature and is finding that they prefer this new view engine syntax over the existing ASP.NET MVC default view engine or over web forms, and if so, why? What about CSHTML gives you an advantage over MVC or web forms, or vice versa?
Just curious to hear people's take on it.

One of the benefits is that Razor views can be rendered inside unit tests, this is something that was not easily possible with the previous ASP.Net renderer.
From ScottGu's announcement this is listed as one of the design goals:
Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or web-server, and can be hosted in any unit test project – no special app-domain required).

Ex Microsoft Developer's Opinion
I worked on a core team for the MSDN website. Now, I use c# razor for ecommerce sites with my programming team and we focus heavy on jQuery front end with back end c# razor pages and LINQ-Entity memory database so the pages are 1-2 millisecond response times even on nested for loops with queries and no page caching. We don't use MVC, just plain ASP.NET with razor pages being mapped with URL Rewrite module for IIS 7, no ASPX pages or ViewState or server-side event programming at all. It doesn't have the extra (unnecessary) layers MVC puts in code constructs for the regex challenged. Less is more for us. Its all lean and mean but I give props to MVC for its testability but that's all.
Razor pages have no event life cycle like ASPX pages. Its just rendering as one requested page. C# is such a great language and Razor gets out of its way nicely to let it do its job. The anonymous typing with generics and linq make life so easy with c# and razor pages. Using Razor pages will help you think and code lighter.
One of the drawback of Razor and MVC is there is no ViewState-like persistence. I needed to implement a solution for that so I ended up writing a jQuery plugin for that here -> http://www.jasonsebring.com/dumbFormState which is an HTML 5 offline storage supported plugin for form state that is working in all major browsers now. It is just for form state currently but you can use window.sessionStorage or window.localStorage very simply to store any kind of state across postbacks or even page requests, I just bothered to make it autosave and namespace it based on URL and form index so you don't have to think about it.

Everything is encoded by default!!! This is pretty huge.
Declarative helpers can be compiled so you don't need to do anything special to share them. I think they will replace .ascx controls to some extent. You have to jump through some hoops to use an .ascx control in another project.
You can make a section required which is nice.

The biggest benefit is that the code is more succinct. The VS editor will also have the IntelliSense support that some of the other view engines don't have.
Declarative HTML Helpers also look pretty cool as doing HTML helpers within C# code reminds me of custom controls in ASP.NET. I think they took a page from partials but with the inline code.
So some definite benefits over the asp.net view engine.
With contrast to a view engine like spark though:
Spark is still more succinct, you can keep the if's and loops within a html tag itself. The markup still just feels more natural to me.
You can code partials exactly how you would do a declarative helper, you'd just pass along the variables to the partial and you have the same thing. This has been around with spark for quite awhile.

Related

Migrating from ASP.NET WebForms to MVC [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I've read plenty of questions and articles stating that converting from ASP.NET Webforms to MVC is near enough impossible. However I think my scenario is different.
I foolishly started working a project about a year ago in Webforms, but the approach I took (as far as I understand) is very MVC like. I have disabled forms validation, don't use any postbacks, use URL re-writing and all page changes are AJAX requests that load the page contents of ContentPlaceHolders (using a small hack, overriding the RenderControl method). I've also used my own ORM and RESTful Service API in seperate projects, referenced in the website.
Now the system works really well, the pages are partially refreshed fine and the url's are changed when the ajax calls are made, so when the page is refreshed, it looks exactly the same.
Now I've just been told I need to learn MVC for a new big project (but I have to finish another project first), but I've done a bit of reading on the subject and started a few Hello World apps, and it seems that the idea of ASP.NET MVC is pretty much exactly what I have already created.
Would StackOverflow still recommend against converting the Webforms application to MVC? Are there any other benefits of converting to MVC, besides best practices?
I have a very large and old ASP.NET WebForms application (which was originally written for .NET 1.1!) and have enabled MVC to work in it, side-by-side. I've been writing new features using MVC, and converting old WebForms features to MVC controllers and views.
I ran into a few little issues concerning URL authorization and running in IIS integrated mode, but once I understood the issues they were fairly easy to work out. So nearly impossible? Certainly not!
I can't tell you if it's worth your time to convert it, since I don't know the size, scope or nature of your application, or any business constraints. However, moving to MVC has been a considerable boon to ease of development and quality (since it is easier to compartmentalize and unit test). Not to mention, the features I've written (or rewritten) in MVC are much cleaner, faster, and responsive than the WebForms equivalents.
I'm excited to move it from MVC v2 to v3, and convert to Razor views. So would I? I if I were you and I had the time, I'd do it.
Here's a question I posted that outlines the process and one of the more significant problems I had in the conversion. Migrating legacy ASP.NET to MVC 2 (RC): HttpApplication events not firing, User principal is null
I've recently converted a medium size project from WebForms to MVC. I would not recommend doing that on your first MVC project, but once you get the hang of it there really is nothing stopping you from (gradually) converting a WebForms app to MVC.
One of the major benefits I've noticed is speed. By throwing out the viewstate, databinding and web control weirdness you'll end up with a much faster application.
Of course there's also the better known benefits like testability and full control over the generated html.
WebForms and MVC share the same basic ASP.NET platform, so they are really not as incompatible as you've read.

ASP.NET learning path [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I want to ask experienced ASP.NET developers about how to climb the learning curve of ASP.NET.
I am an experienced C++ and C# developers with no web application experience.
I found ASP.NET MVC and ASP.NET are two different technologies. I just want to ask:
Whether these two technologies will co-exists or MVC will replace
ASP.NET?
If I want to learn ASP.NET MVC. Do I need to learn ASP.NET as a prerequisite?
Can you recommend some learning resources? Book? Video? Not paid Microsoft training :(
Many thanks
First of all ASP.NET is request/response pipeline. This means that you are given access to the request and response streams as well as some provisions like, session, cache, security, etc.
On top of this there are 3 frameworks in charge for generating HTML. The first and oldest is known as ASP.NET Web Forms. Because it was the only one it is sometimes called ASP.NET but this is not correct in the current state of things. ASP.NET MVC is the second one and there is a third one known as ASP.NET Web Pages. All 3 of these share the same core ASP.NET request/response pipeline and the APIs for Session, Cache... What is different is how they generate HTML.
You can check my answer to this question for more info.
Asp.Net Web Forms and Asp.Net Web Pages
And to answer your concrete question - no Web Forms is not going away. A lot of people use it, MS are releasing new versions.
Web Forms is pretty good for people with desktop background because it uses a control model familiar to desktop devs and also has something that simulates state. It also requires less knowledge of HTML, JS, CSS. ASP.NET MVC is kind of the opposite. It gives you a lot of control but requires a lot of knowledge about the web.
I personally prefer Web Forms to MVC for a variety of reasons that I will not list here but even Web Forms supporters (and especially me) will admit that Web Forms is pretty bad way to learn about the web because it abstracts a lot of things. This gives you productivity, security, etc. but can result in cases of leaky abstraction if you don't know how the underlying framework works and it is pretty easy to skip learning the details because you know stuff just works... until it breaks and then you don't know where to start.
Ultimately the choice is yours but if you start with Web Forms be sure to learn about HTTP verbs, cookies, raw response stream, http headers, html form/submit model inline css vs separate files and javascript out of the context of Web Forms and make sure you know how Web Forms automates these.
1) Whether these two technologies will co-exists or MVC will replace ASP.NET?
The official position of Microsoft today is that those two technologies will coexist. ASP.NET MVC will not replace classic ASP.NET. At least Microsoft will continue shipping new features in ASP.NET.
2) If I want to learn ASP.NET MVC. Do I need to learn ASP.NET as a prerequisite?
Not necessarily but it will be better if you learned it because as ASP.NET MVC is based on ASP.NET kernel and it will help you be a better understand the underlying technology.
3) Can you recommend some learning resources? Book? Video? Not paid Microsoft training :(
http://asp.net/mvc is a good start.
Can't say if one is going to rule the other one out.
But the easiest to learn is asp.net MVC.
Pro ASP.NET MVC 3 Framework
this is a good book to learn it.
http://www.w3schools.com/aspnet/default.asp
http://aspauthors.com/aspnetbyexample/
http://www.exforsys.com/tutorials/asp.net.html
Some links which may useful to you.
Darin gives you good answers on 1 and 3, but i disagree some on 2:
2) If I want to learn ASP.NET MVC. Do I need to learn ASP.NET as a prerequisite?
No. ASP.NET WebForms (often reffered to as just ASP.NET) has a VERY different paradigm.
While ASP.NET WebForms tries it best to hide all the web (like POST vs. GET, the HTML, how to maintain state) stuff from you, ASP.NET MVC is dependant on knowing and understanding the same things. Learning aboutWebForms' ServerControls and ViewState are of little help.
There are of course parts of the ASP.NET stack that you'll encounter in both WebForms and MVC. The different state mechanisms (session, application, cookies etc.), the Server, Reguest and Response objects, caching mechanisms, jQuery etc. are used in both places.

Umbraco vs Sitefinity [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am getting a large website developed. The develop has asked me which do I prefer either sitefinity or umbraco. The site will be similar to wikipedia where users can come and edit pages without having to login. I would like to ask your opionions on these two csm systems and which one would you recommend for content website with a community feel and wiki features. Thanks
I disagree with #IrishChieftain's answer and would most certainly go with Umbraco!
I've built a number of websites in Umbraco (and have got my certification) and I have to say I absolutely love it!
XSLT is very easy to learn unless you come across some really complex functionality. But even then, you can resort to ASP.NET if you don't want to learn XSLT.
If it's a non-commercial (charity?) site, you may be able to obtain the community version of Sitefinity for free if you display their logo in the footer. Sitefinity has a lot to offer, including an ORM.
Umbraco on the other hand has, for me personally, an unhealthy reliance on XSLT to customize the content. That was the main reason I didn't go with it.
I would go for Sitefinity or N2 for this.
Contrary to what others have suggested, I find the use of XSLT in Umbraco advantageous on numerous levels. In particular the time it takes to make changes and see their results is very quick. Just create transform and put a macro in your page and you can see the results. You get access to all the site data as necessary directly in the transform. Also, the fact that you are just working in HTML within the XSL transform means that it would be easy for a non .NET web developer to make changes too. I've found that although this is a .NET based CMS there is little reason to perform anything in code so you only really have to have open the CMS and your favourite text editor (I'd suggest using a text editor and accessing static files this way (through FTP or whatever if you're not logged in to the machine the CMS is on) rather than through the CMS interface.
If you're looking for a CMS for a large website and with wiki features, look at Kentico CMS. It was designed for large number of documents and it's the most advanced .NET CMS I have seen.
It has a built-in user-contribution module that allows public users to create new content items from the live site and you can control who can do that (all/authenticated/selected roles) and what type of content items (news/pages/knowledge base articles) they can create. Kentico has a free version, but for this type of functionality, you would need a paid license. Still, if it meets your needs for user contributed content, it may pay for itself very quickly since AFAIK no other .NET CMS has this built-in.
Umbraco was possibly the worst CMS a few years back when it was in version 2. Things have changed though and, for me, it jumped to the top of the list when it hit version 4. I find Umbraco to be the easiest CMS to manage and develop in. The XSLT is probably the hardest thing to get used to here, but like others mentioned it isn't a show stopper because you can still do everything using Umbraco data access layer. The one thing i absolutely love about it is how easy it is for the end user. The UI is very intuitive and easy to grasp. The only downside i see with Umbraco is bugs and there are a whole lot of them even in version 4 releases. Most of them are UI bugs. However, some do affect advanced features such as packages. I would still go with Umbraco if i had to pick a choose a CMS for a project of any size.

Where can I find some quality tutorials that take me through the anatomy of an MVC view? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
My background is mostly in desktop applications on the Microsoft platform. I've been working a lot with ASP.Net MVC lately and completely skipped over learning webforms. I find I'm having the most trouble (not being a web guy) with writing my views in MVC. How proficient should I be with HTML and javascript to write good views in MVC? Also, is the standard Webforms view engine what I should go with, or would I have an easier time using the Spark view engine, given my background?
You'll need a good understanding of HTML, JavaScript (and jQuery most likely) and CSS for most web work these days. It doesn't matter if you are using ASP.Net MVC w/ Spark, default engine or other technologies like PHP. In the end, the browser only understands HTML, JavaScript and CSS, the other stuff is just to assist in creating that final output, but you still need to understand what you want to be generating.
Regarding view engine, if you are working on learning for future use rather then for an immediate project you want to put into production ASAP, I'd suggest taking a look at Microsoft's upcoming view engine Razor.
http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx
It is being built for the ASP.Net MVC 3 release taking lessons learned from Spark, NHaml and the default view engine.
From the article:
Design Goals
We had several design goals in mind as we prototyped and evaluated “Razor”:
Compact, Expressive, and Fluid: Razor
minimizes the number of characters
and keystrokes required in a file,
and enables a fast, fluid coding
workflow. Unlike most template
syntaxes, you do not need to
interrupt your coding to explicitly
denote server blocks within your
HTML. The parser is smart enough to
infer this from your code. This
enables a really compact and
expressive syntax which is clean,
fast and fun to type.
Easy to Learn: Razor is easy to learn and enables you to quickly be productive with a minimum of concepts. You use all your existing language and HTML skills.
Is not a new language: We consciously chose not to create a new imperative language with Razor. Instead we wanted to enable developers to use their existing C#/VB (or other) language skills with Razor, and deliver a template markup syntax that enables an awesome HTML construction workflow with your language of choice.
Works with any Text Editor: Razor doesn’t require a specific tool and enables you to be productive in any plain old text editor (notepad works great).
Has great Intellisense: While Razor has been designed to not require a specific tool or code editor, it will have awesome statement completion support within Visual Studio. We’ll be updating Visual Studio 2010 and Visual Web Developer 2010 to have full editor intellisense for it.
Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or web-server, and can be hosted in any unit test project – no special app-domain required).
For ASP.Net MVC 3 Preview 1, take a look at http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx
Specifically on the subject of View Engines, if you're looking to introduce code blocks into your views, then Razor would be the neatest way of doing that.
I guess, given your background, the next question would be - "how do I know if I want to introduce code blocks into the view?" - the answer I'm afraid can only come to you with a lot of pain an experience. Many people have written blog posts explaining the dangers of code blocks mixed in with markup that leads to a nightmare commonly referred to as Tag Soup.
All that Razor (and Webforms for that matter) does for you is bring the power of the entire C# or VB.Net languages into the view in a way that prescribes abundant usage. This is what leads to the Tag Soup problem.
But it seems there are still die-hards out there under some kind of illusion that you can actually keep your views clean in the long term by using this method. If you are working on the code alone, and forever, then I'd tend to agree that it is possible, but only then with the mind-numbingly depressing levels of concentration and determination.
If however, you'd like to keep you views for markup with the code abstracted away to where it can be less tempting to put a "quick fix in here" and a "hack in there", then I'd highly recommend that you skip over the code-centric view engines and go with Spark.
In terms of answering your question directly, you can find plenty of tutorials from beginner to advanced. Here are some of the ones I'd recommend in blog and video formats:
http://blogs.msdn.com/b/coding4fun/archive/2010/10/04/10070953.aspx - An incredibly comprehensive and accurate comparison of View Engines prepared by Jason Haley
http://vimeo.com/13027275 - A beginners' introduction to Spark given at NDC2010 by the author, Lou DeJardin himself
http://vimeo.com/13027900 - Another video for more advanced usage of Spark also given by Lou at the same conference.
http://blog.robertgreyling.com/2010/07/is-razor-just-wolf-in-sparks-clothing.html - A blog post where I directly compare and contrast Razor and Spark
http://blog.robertgreyling.com/2010/08/spark-bindings-are-you-tired-of-eating.html - A blog post I wrote about cleaning up your markup
http://blog.robertgreyling.com/2010/08/elegant-mvc-with-spark-way-views-were.html - An online session I prepared for C4MVC as an educational and awareness exercise.
Anyway, I hope that gives you enough to make an informed decision.
Best of luck in your dabblings!
Rob G

Web App - Dashboard Type GUI - Interface [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm looking to create a dashboard type gui for a web application. I'm looking for the user to be able to drag and drop different elements (probably either image buttons, anchor tags, or maybe just divs) to different (defined) places and be able to save their setup (in a cookie or on the server). I'm working with c# in the .Net 2.0 framework. I've tried using mootools but their recent update has left their drag/drop capabilities un-useful for me. I'm looking for a bit of direction because I know there is something out there that is just what I'm looking for so I wont have to build from scratch.
Thanks.
I have been looking at this kind of functionality myself recently and have decided on using jQuery with the help of jQuery UI. I came across a large amount of information that also suggested Yahoo UI (YUI), I had already started learning jQuery due to the AJAX support that it offers, so I stuck with it.
jQuery UI Site
jQuery UI Documentation
Example of a drag and drop screen layout with jQuery UI
Introduction to jQuery UI
If you decide to use the YUI javascript library, here is a link to a vast amount of videos to help get you started.
http://developer.yahoo.com/yui/theater/
If you still want to give MooTools a second chance, I'd recommend taking a look at Mocha UI.
I prefer using jQuery for AJAXy stuff like that. It also has a lot of very good plugins that make writing client-side code very easy.
Here is the plugin page specifically for Drag-n-Drop.
http://plugins.jquery.com/project/Plugins/category/45
Ajax callback are also very easy so saving the setup should be fairly easy as well.
I used the Microsoft ASP.Net Ajax and AjaxControlToolkit to do something like this. They have a ResizeableControl and a DragPanel. I used these, then hosted an IFrame inside the panel to display the content.
Worked pretty well.
This site:
http://www.asp.net/learn/videos/default.aspx?tabid=63#ajax
Has lots of tutorial videos that show you how to get started using the controls.
You might want to look at DropThings on Codeplex.

Categories