Razor
What Happened To @Helpers In ASP.NET Core?
calendar_today 21 November 2019 13:11
When you port your Razor-based application to ASP.NET Core, whether its an
MVC application or a Web Pages application, you might notice that adding a
@functions
block to your .cshtml file works as expected,
but any attempt to add a
@helpers
block doesn't work at all.
Razor Pages - Getting Started With The Preview
calendar_today 15 May 2017 20:52
Current users of ASP.NET Web Pages have been eagerly awaiting news on what ASP.NET Core holds for them (if my inbox is anything to go by). The roadmap suggested that a new version of Web Pages would be forthcoming after the initial release of .NET Core, but that item was subsequently removed. Instead, a new cross platform page-centric web development model called Razor Pages has been made available in preview form. Here, I show you how to get started with it and explore its similarities with Web Pages. In future articles, I will take a closer look at the wide range of differences.
Usage of the @ (at) sign in ASP.NET
calendar_today 22 January 2015 13:54
The number of places where you might use or encounter the @
sign in ASP.NET has grown over the last few years and its exact purpose in all circumstances still seems to cause confusion. Here's an overview of the most common places that it crops up, and guidance on its correct usage.
Using ASP.NET Identity with Razor Web Pages
calendar_today 04 July 2014 07:27
ASP.NET Identity is the new membership system for ASP.NET applications and is the recommended system for new MVC 5 and Web Forms projects. Among other things, it moves membership away from being dependent on System.Web, which is the general direction that the next version of ASP.NET is taking. News on how the Web Pages framework will be impacted by this evolution in ASP.NET is scarce at the moment, and so is information on how to incorporate ASP.NET Identity into a Razor Web Pages site. This article demonstrates the steps required to make use of the ASP.NET Identity framework in your Web Pages application.
Migrating Classic ASP To ASP.NET Razor Web Pages Part Three- Include Files And Reusable Code
calendar_today 10 March 2014 13:23
This is the third in a series of articles that explore how to migrate classic ASP web sites to the ASP.NET Web Pages framework. I covered Razor syntax and data access in the previous articles. This article shows how to deal with reusable code that typically inhabits include files in classic ASP.
Migrating Classic ASP To ASP.NET Razor Web Pages Part One- Razor Syntax And Visual Basic
calendar_today 24 February 2014 13:25
You have a classic ASP application that needs migrating to ASP.NET. You are comfortable working with classic ASP. but ASP.NET is fairly new to you. So what do you do? This article is the first in a series that looks at your options and proposes an approach to the migration that follows the path of least resistance.
Adding a New Row In The Razor WebGrid
calendar_today 23 January 2014 08:10
The Razor WebGrid isn't just used for displaying data. I have already looked at how to edit data inline within the WebGrid, so this article looks at how to add new rows of data. within a rendered grid.
Request Validation In ASP.NET Web Pages
calendar_today 18 December 2013 11:24
Cross Site Scripting (XSS) attacks are the third on the Open Web Application Security Project's (OWASP) 2013 list of security vulnerabilities. This article looks at the defence mechanisms built into ASP.NET that protect against such attacks and how you can disable those defences in ASP.NET Razor Web Pages in a safe manner when you need to.
Check Duplicate User Names In ASP.NET Web Pages Sites
calendar_today 29 November 2013 15:22
The Web Pages Starter Site template provides a useful starting point for developing a Razor Web Pages site that includes membership. But it doesn't include any mechanism for preventing duplicate user names. This article offers one solution to the problem that uses jQuery.
Posting Data With jQuery AJAX In ASP.NET Razor Web Pages
calendar_today 06 November 2013 19:38
There have been a few questions recently about what you can post to the server using jQuery AJAX and where to find whatever you posted. This article looks at using the jQuery ajax method in ASP.NET Razor Web Pages and explores how different options have different results.
Saving jQuery Sortables In ASP.NET Razor Web Pages
calendar_today 28 October 2013 20:04
jQuery Sortables offer a way to specify the order of a collection of items through an easy drag and drop interface. I have just been working on the next release of Web Pages CMS and am in the process of implementing Sortables for managing the display order of menu items. This article looks at how they can be used in Razor Web Pages and shows one way of saving the resulting order to a database.
Managing Checkboxes And Radios In ASP.NET Razor Web Pages
calendar_today 14 October 2013 21:04
Checkboxes and radio buttons cause more confusion than any other form control in ASP.NET Razor Web Pages. This article takes an in depth look at them and tackles the most frequently asked questions that they generate.
Implementing Customers Also Bought In ASP.NET Web Pages
calendar_today 01 August 2013 15:32
Most successful e-commerce sites implement a mechanism that draws the customer's attention to other products that might be of interest to them. These products are selected on the basis that shoppers who purchased the item currently being viewed by the customer also bought other products. This article looks at a away of implementing this kind of facility in an ASP.NET Web Pages site.
How To Check If A Query Returns Data In ASP.NET Web Pages
calendar_today 03 July 2013 14:01
If you execute a query against a database, you need to know if any data was returned. But what is the best way to test for the presence of data when using the Web Pages Database helper?
A CKEditor File Browser For ASP.NET Web Pages
calendar_today 16 May 2013 14:00
CKEditor is one of the most popular rich text editors available. Out of the box, there is no file browser to help with selecting images, but you can purchase an add-on from them - CKFinder. Alternatively, you can build your own file browser component.
Adding A Footer To The Razor WebGrid
calendar_today 25 February 2013 19:43
Whether you are using the Razor WebGrid in an ASP.NET Web Pages site, or an MVC application, you may well want to display tabular data at some point in which case you are likely to turn to the Razor WebGrid helper. And if you want to do that, you might also want to add a footer to the rendered table. Here are some ways that you can accomplish that task.
Razor Web Pages E-Commerce - Adding A Shopping Cart To The Bakery Template Site
calendar_today 15 February 2013 19:31
The ASP.NET Web Pages Bakery template site is designed as a starting point for a site that displays products. It also features an order form for customers to specify a quantity for a specific product and provide their shipping address. The site doesn't provide for multiple product selection. If you want a shopping cart for the Bakery site, you need to create it yourself. This article looks at the design considerations behind an effective shopping cart, and shows how to build one.
Practical Recursion in ASP.NET Web Pages with WebMatrix
calendar_today 22 January 2013 14:44
Recursive methods are those that call themselves, and they can be applied to solve a number of common practical problems, particularly ones that involve the management and display of hierarchical data. This article explores some of those scenarios and shows how to design recursive helpers and functions that can be used in Web Pages sites.
SignalR And Knockout In ASP.NET Web Pages Using WebMatrix
calendar_today 27 December 2012 20:17
SignalR is a library that simplifies the creation and management of persistent connections between web servers and clients. This facilitates the development of applications that can display updates to data held on the server in real-time. Chat applications are the most obvious beneficiaries of this technology, but line-of-business applications that need to report availability to users can benefit too. Here, I look at extending the canonical SignalR chat example to incorporate a "who's typing" feature, and I also extend my previous Knockout example to use SignalR.
Exporting The Razor WebGrid To PDF Using iTextSharp
calendar_today 20 December 2012 13:31
This article looks at how you can provide your users with the ability to export the contents of a Razor Web Pages WebGrid to a PDF file using the popular free PDF library, iTextSharp.
Exporting The Razor WebGrid To Excel
calendar_today 17 December 2012 20:17
This article looks at how you can provide your users with the ability to export the contents of a Razor Web Pages WebGrid to an Excel file.
Enhancing The WebGrid With Sort Arrows
calendar_today 14 December 2012 19:24
The Web Pages WebGrid offers sorting capability out of the box. However, it's not always obvious to the user on which column the grid data is being sorted at any one time, nor the direction in which it is being sorted. The convention is to provide arrows in the column header to act as a clear visual cue. This article looks at a three ways in which you can enhance your grids with sorting arrows.
Inline Editing With The WebGrid
calendar_today 13 November 2012 10:37
Unlike the Web Forms GridView control, the Web Pages WebGrid doesn't offer anything by way of inline editing capability. This article looks at one approach to solving that requirement through the addition of a sprinkling of jQuery.
Cleaner Conditional HTML Attributes In Razor Web Pages
calendar_today 23 October 2012 21:27
Every so often, you will want to conditionally render HTML attributes or their values within your Razor Web Pages based on the outcome of some runtime logic. Often, the logic required to manage this can become messy and lead to unnecessary spaghetti code. This article explores a few common scenarios and provides some solutions, as well as introducing a nice new feature that was released as part of Razor v 2.0.
Validation In Razor Web Pages 2
calendar_today 14 June 2012 12:47
The new release of ASP.NET Web Pages - version 2 - doesn't include many obvious changes, but the most significant one is an enhanced Validation system. A couple of new classes have been introduced, and Web Pages validation now works with the MVC Unobtrusive jQuery validation library. This article explores the new validation system and sees what it brings to the party.
Using Knockout With Razor Web Pages In WebMatrix 2
calendar_today 09 June 2012 11:40
Knockout is an increasingly popular JavaScript UI library. Its popularity is likely to increase among ASP.NET developers soon as it comes as part of some of the new MVC 4 site templates. This article looks at what Knockout is, what problems it is intended it solve and how to use it in an ASP.NET Razor Web Pages site built in WebMatrix.
Efficiently Displaying Hierarchical Data With The jQuery Accordion In Razor Web Pages
calendar_today 03 June 2012 10:30
A frequent requirement is to display data hierarchically, such as products by category. This article shows how to use LINQ to Objects and the jQuery Accordion to display the result of a database query in such a fashion within Razor Web Pages.
View Model Design And Use In Razor Views
calendar_today 26 May 2012 23:21
The recommended practice for transferring data to and from views in ASP.NET MVC is to use a View Model. But what is a View Model? How to you design one and how should they be used? This article attempts to provide answers to those questions.
More Flexible Routing For ASP.NET Web Pages
calendar_today 01 February 2012 21:52
The built-in Web Pages routing system offers a fair degree of freedom in terms of how friendly URLs can be constructed and managed. However, the major limitation with the standard routing mechanism is that it relies on matching segments of the URL to files on disk. ASP.NET MVC and Web Forms enjoy a much more flexible routing system. This article looks at a Package that brings full ASP.NET routing control to Web Pages and examines how to use it.
Using The Themes Helper In Razor Web Pages
calendar_today 02 January 2012 18:31
Web site skinning is a concept where by a web application user can personalise their experience, by choosing from a selection of prepared themes or skins. Each theme or skin might offer a different design, or content, or both. ASP.NET Web Forms has included a comprehensive Themes framework since version 2.0. WebMatrix developers can find Themes management functionality in the ASP.NET Web Helpers Library package available through the Package Manager. This article looks at how the Themes helper works.
Building A Razor Web Pages Site With Database First And Entity Framework
calendar_today 30 December 2011 15:25
Since I published an item covering Code First development with Entity Framework and WebMatrix, I have had a few requests to provide a guide to working with the Entity Framework from a database first point of view. This post answers those requests and provides a step by step guide to getting up and running with a WebMatrix web site based on the Northwind sample database that comes with SQL Server CE 4.0.
HTML Helpers For Forms In Razor Web Pages
calendar_today 25 December 2011 11:27
A nugget that has remained partially hidden from view within the Web Pages framework is the HtmlHelper class. Parts of this class peek out in the template sites provided in WebMatrix where validation is performed and related messages displayed, but a vast range of methods designed for rendering form inputs are often overlooked in tutorials, blog articles and books (mine included). This article provides an overview of Web Pages HTML Helpers, and digs into one or two in more detail.
Globalization And Localization With Razor Web Pages
calendar_today 10 October 2011 21:35
Globalization is the process of preparing your site so that it is accessible to as wide an audience as possible. This is largely achieved by presenting content in the native language of the visitor. This article explores how you can approach this task within the ASP.NET Web Pages framework.
Entity Framework Code First Development With WebMatrix
calendar_today 05 September 2011 17:27
The existing data access story for WebMatrix is the Database Helper. Microsoft's recommended data access technology going forward is the Entity Framework (EF). This article explores how to use the Code First capability offered by EF within an ASP.NET Web Pages application.
The WebGrid - Efficient Paging And Sorting With SQL CE 4.0
calendar_today 28 August 2011 22:46
A problem inherent in the existing version of the WebGrid is that it is not very efficient when it comes to paging data out of the box. If you have 10,000 rows of data, and you want to display 10 rows per page, all 10,000 rows are retrieved from the database for each page. The grid works out how to only show the current 10, and wastes the other 9,990 rows. That's a fair sized overhead on each page. Ideally, you should only retrieve the data you need for each page. This article examines how you can do that with the existing WebGrid and a SQL CE database, while still maintaining sorting capabilities.
Displaying Search Results In A WebGrid
calendar_today 27 August 2011 16:57
A number of people have run into problems when trying to combine a search or filter form, and a WebGrid. The main issue that arises is when paging or sorting the search result or a filtered subset of it. Here, I look at the cause of the problem and what you can do about it.
How To Maintain Scroll Position When Paging Or Sorting A WebGrid
calendar_today 23 August 2011 21:13
This snippet is one in a series showing how to use jQuery to enhance the behaviour of a Web Pages WebGrid. This example shows how to maintain scroll position on the page when paging or sorting the WebGrid.
How To Make A WebGrid Row Clickable
calendar_today 23 August 2011 11:23
This snippet is one in a series showing how to use jQuery to enhance the behaviour of a Web Pages WebGrid. This example shows how to make an entire row clickable so that the user is taken to another page that displays details of the selected row.
jQuery Autocomplete with Razor Web Pages and a SQL CE Database
calendar_today 16 August 2011 09:23
There are a number of autocomplete solutions for jQuery, including the widget that comes as part of the jQuery UI library. This article looks at incorporating the jQuery UI Autocomplete widget into a Razor-based ASP.NET Web Pages site.
WebMatrix and jQuery Forms Part 2 - Editing Data
calendar_today 06 August 2011 17:33
This article continues on from one I wrote a while ago, showing how to use jQuery to create a data entry form in conjunction with the WebGrid. The original article prompted a number of requests to show how to extend the example to provide editing functions, and now I have found some time to answer those requests.
Generating RSS and ATOM Feeds In WebMatrix
calendar_today 12 April 2011 12:36
I've previously looked at how to generate RSS feeds for both Web Forms and MVC using a variety of techniques, so it is only right that I look at a couple of ways to do this in Web Pages - the Razor based web development model supported by WebMatrix.
The Difference Between @Helpers and @Functions In WebMatrix
calendar_today 20 March 2011 09:42
This is another post which was inspired by a recent question in the ASP.NET forums, when someone asked what the difference is between @functions and @helpers in ASP.NET Web Pages. Here, I look at both of these contructs and explain what they are, how they are different, and how each should be used appropriately.
The WebGrid Helper - Making Selections
calendar_today 13 January 2011 14:08
The WebGrid helper, introduced via ASP.NET Web Pages, provides a means for displaying tabular data easily. This article examines how to enable selection within the WebGrid at row level.
Razor, Cascading Select Lists and jQuery Templates - A New Twist
calendar_today 04 January 2011 22:20
jQuery Templates enable easy client-side generation of html. When combined with JSON data or other JavaScript objects, jQuery Templates provide a way to create a dynamic data-driven site without any server-side code whatsoever. However, in this article I will look at how they can be used to produce cascading select lists in a Razor Web Pages site.
WebMatrix - URLs, UrlData and Routing for SEO
calendar_today 20 December 2010 12:56
There is a certain amount of debate surrounding the importance of friendly URLs in terms of Search Engine Optimisation and improving your ranking. One thing is certain - having friendly URLs helps users to identify whether the content at the end of a link to your site is likely to be relevant to them or not. This article examines how you can make use of the built-in support for Routing provided by ASP.NET Web Pages to not only create friendly URLs, but to work with parameters as well.
Nested Layout Pages with Razor
calendar_today 17 December 2010 13:27
Razor Layout pages are the equivalent to MasterPages in ASP.NET Web Forms and the Web Forms View Engine within ASP.NET MVC. Just as it is possible to nest MasterPages, it is also possible to nest Razor Layout pages. This article explores the process required to achieve nesting of Layout pages using the Razor View Engine in MVC 3, or WebMatrix Web Pages sites.
Building Mobile Apps with WebMatrix and jQuery Mobile
calendar_today 12 December 2010 21:52
jquery Mobile was launched just a month or so ago, and is designed to make it as easy to build JavaScript-enabled web applications for mobile phones as for the desktop browser. Still in Alpha, the library has a way to go, but it already offers a rather interesting experience when used as part of a mobile phone targeted web application. Here's a first look at how to use jQuery Mobile with WebMatrix to build a mobile web application.
WebMatrix - Working With The JSON Helper
calendar_today 15 October 2010 18:51
Javascript Object Notation (JSON) is a data exchange format which really grew in popularity as AJAX libraries took off. It's lightweight and human readable, and is a great way of transferring data structures between the browser and the server. The JSON Helper was added in WebMatrix Beta 2, and this article looks at its main methods, and how they can be used.
WebMatrix - Protecting Your Web Pages Site
calendar_today 10 October 2010 20:04
Your Web Pages site is under threat. There are people out there who want to break into restricted areas, download files they shouldn't have access to, mess up your database and steal your passwords. Worse still, they want to use your application as a gateway to the web server so that they can take full control over it. This article examines those threats and how you can protect your application against them.
WebMatrix - Database Helpers for IN Clauses
calendar_today 11 September 2010 09:35
There are times when you want to query a database for records matching a range of values, but you do not know what those values are, or even how many there are at design time. You could dynamically build your WHERE clause with multiple ORs, or you can use the SQL IN clause - except that the current database helpers in WebMatrix don't make this easy. It's about time that was fixed....
Looking At The WebMatrix WebGrid
calendar_today 08 August 2010 09:33
One of the most useful helpers provided by ASP.NET Web Pages via WebMatrix is likely to be the WebGrid, which is designed for displaying tabular data. Still in Beta 1, documentation is sparse, so here's a more detailed look the WebGrid Helper.
Inline Razor Syntax Overview
calendar_today 30 July 2010 15:27
With the launch of WebMatrix, and the announcement of the new Razor View Engine for the next version of ASP.NET MVC, here's a quick guide to Razor syntax.
Save And Retrieve Files From a Sql Server CE Database with WebMatrix
calendar_today 09 July 2010 20:28
A perennial choice that web developers have to make is whether to store uploaded files to the file system or a database. Each method has its pros and cons, and the debate over which approach is best continues to rage. This article will not add to the noise. It will simply demonstrate how to upload files to the Sql Server CE database which is the default option in Web Pages, and how to retrieve them for users again.
WebMatrix - Consistent Look And Feel With Razor
calendar_today 07 July 2010 22:04
Most web development frameworks provide features that assist with creating a consistent look and feel across pages, or make provision for managing reusable partial content, such as headers and footers. The Web Pages framework is no exception. This article examines the core features offered by its Razor view engine for handling templated layouts and common blocks of content.
Get The Drop On ASP.NET MVC DropDownLists
calendar_today 07 January 2010 21:27
DropDownLists in ASP.NET MVC seem to cause a fair amount of confusion to developers fresh from Web Forms World. This article looks to provide you with all (well, most) of what you need to know to get your DropDownLists working in ASP.NET MVC.