background preloader

MVC Extensions

Facebook Twitter

Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine. Optional Razor Sections with Default Content - Marcin On ASP.NET. Razor, Nested Layouts and Redefined Sections - Marcin On ASP.NET. In a recent post I introduced a technique for dealing with optional Razor sections and default content.

Razor, Nested Layouts and Redefined Sections - Marcin On ASP.NET

In this post I will expand upon that technique and describe a way of working with sections across nested layout hierarchies. If you are not familiar with sections, layout pages, or my technique then go ahead and read that post to catch up. One aspect of the relationship between layout pages and sections in Razor that a fair number of people might find surprising is that a section defined in a content page can only be used in its immediate layout. There is implicit scoping going on that prevents certain use cases. Take the following example: In the above example you can certainly call RenderSection("SubSection") in _MasterLayout.cshtml, as well as call RenderSection("ContentSection") in _SubLayout.cshtml. T4MVC/T4MVC. MVC extension : SubmitButton.

Introduction.

MVC extension : SubmitButton

Which MVC extensions Telerik vs DevExpress. CheckBoxList(For) - A missing MVC extension. Check out official website with live examples and documentation: mvccbl.com Latest Version (for .NET 4.0 or 4.5 and MVC4) Install via NuGet Package Manager Console: Install-Package MvcCheckBoxList Download binary (MvcCheckBoxList.dll) Download MvcCheckBoxList.zip Download sample MVC project with extension's stable source code Contents Introduction One of the cool features of Microsoft MVC web development framework since its inception, was its rich Html helpers library.

CheckBoxList(For) - A missing MVC extension

Its all been good and easily customizable, until developers been eventually reaching one blank spot... Creating custom HTML helpers for ASP.NET MVC. HTML Helpers with Extension Methods. Introduction In the last article, I explored Creating Custom HTML Helpers by creating a static method that returns a string.

HTML Helpers with Extension Methods

In this article, I will explore HTML Helpers with Extension Methods. The HtmlHelper class provides a set of helper methods that generate plain HTML and return the result as a string. The extensions add helper methods for creating forms, rendering HTML controls and rendering partial views and they are located in the System.Web.Mvc.Html namespace. I will create a submit confirm button that renders an HTML <input type=”submit”> tag as SubmitConfirmHelper class shown below: using System.Web.Mvc; namespace Helpers { public static class SubmitConfirmHelper { public static string SubmitConfirm(this HtmlHelper helper, string buttonText, string alertMessage) { return String.Format( "<input type=\"submit\" value=\"{0}\" onClick=\"return confirm('{1}');\" />", buttonText, alertMessage); } } } Now you can run the project and it will render the form as shown below: Summary.

Telerik MVC : Extending the Telerik HTML Helper - ASP.NET Wiki. Written by John DeVight on 2011-May-18 Last Updated by John DeVight on 2013-Mar-15 Download TelerikBuilderExtensions.cs Last week I wrote a wiki page MVC 3 Razor : Creating Custom HTML Helpers about extending the HTML Helpers to be able to render controls read-only.

Telerik MVC : Extending the Telerik HTML Helper - ASP.NET Wiki

I also needed to extend the Telerik MVC controls to render the Telerik MVC controls read-only as well. I took a look at the Telerik.Web.Mvc.dll assembly using .NET Reflector and looked to see how Telerik extended the HTML Helper with their ViewComponentFactory, what we usually see as the Html.Telerik() method. The ViewComponentFactory creates an instance of a ViewComponentBuilder to "build" the control. Since I wanted to be able to render the Telerik controls as read-only, I overloaded the Render method to take a parameter of bool that indicates whether the control is editable or not. The class that derives from ViewComponentBuilder to render the DropDownList control is the DropDownListBuilder. TagBuilder Class to Build HTML Helpers (C# Stephen Walther introduces you to a useful utility class in the ASP.NET MVC framework named the TagBuilder class.

TagBuilder Class to Build HTML Helpers (C#

You can use the TagBuilder class to easily build HTML tags. The ASP.NET MVC framework includes a useful utility class named the TagBuilder class that you can use when building HTML helpers. The TagBuilder class, as the name of the class suggests, enables you to easily build HTML tags. In this brief tutorial, you are provided with an overview of the TagBuilder class and you learn how to use this class when building a simple HTML helper that renders HTML <img> tags. Dropdown list extension method for HTML helper. Introduction Here the information will describe that how to populate dropdown list.

Dropdown list extension method for HTML helper

It describes about the basic steps for creating an extension method that populates dropdown list in MVC. Background Suppose that we have the requirement to show some specific date format on our views that might be used somewhere else as well. In that case if we use this technique to create an extension method for this purpose and reuse, wherever required. Using the code Here the below code for the extension method is inside a separate file ExtensionMethods which is in the Solution MVCApp. The page where we will use this extension method ,we need to import the namespace for the extension method-in my case it is like- Now here in the view page ,it can be used like: Points of Interest As a rule we need to change the name "SelectedDateFormat" according to the property name being used.

Custom HTML Extensions for MVC3. Download source - 2.01 MB Introduction In this article, I am going to share my experience in creating HTML extensions for ASP.NET MVC3 Razor.

Custom HTML Extensions for MVC3

At the end of the article, you will learn something new on how to create custom extension methods and its advantages. This is part one of two that I want to share with you. Background This article is meant for an intermediate / experienced programmer who has some experience in developing applications in MVC3 Razor/ASPX. There are two ways of creating HTML extensions: