Tag

MVC Archives - Falafel Software Blog

asp-net-core-area-index-view

MVC Areas with ASP.NET Core

By | ASP.NET, ASP.NET Core, MVC, Web | One Comment

Areas in MVC allow you to separate your web application into segments, each with their own set of Controllers and Views, for better organization and intuitive access via routing. I decided to play with this MVC Areas feature in ASP.NET Core and thought I’d share my experience in case it might help others using this feature. My first attempt to use this was to simply add the Areas folder to the root of my application, with a subfolder called Admin with the associated folders for Controllers, Models, and Views: I added a simple AdminController to simulate a separate Administration section…

Read More

Lock Down Content Widgets with UrlKeyPrefix

By | MVC, Sitefinity | No Comments

When you’re working with your content in Sitefinity, a very common practice to display said content is to provide a list and details view. On the page (or pages) containing these views, it is often good to provide a sidebar to provide for additional navigation functionality when users are browsing your content. News articles, for example, can support Tags to help classify stories into various buckets. It’s also nice for users to see a concise list of stories on the sidebar in addition to the more fleshed-out list that the page primarily shows. To accomplish this in Sitefinity appears trivial…

Read More

Working with Hybrid Forms in Sitefinity Widgets

By | .NET, C#, MVC, Sitefinity | No Comments

Throughout the course of web development, you often find yourself in a situation where you need data input from your user. Scenarios range from a simple contact form, to something as complex as a multi-part job application. In either case, Sitefinity offers multiple solutions. The easiest solution, for the simpler forms such as the aforementioned contact form, is to use Sitefinity’s built-in Forms capabilities. Much like with their pages, Sitefinity Forms provide a very simple, powerful way to create and customize even more complex forms for your site. The resulting data is then stored in Sitefinity, and can be set…

Read More

Data Annotations & Entity Type Configuration

By | .NET, C#, News, Web | 3 Comments

We can replace Data Annotations with Entity Type Configuration to make our classes look clean and simple. Majority of developers prefer using View Models for CRUD operations leaving no reason to have Data Annotations defined in our model classes. This article will show you how to replace Data Annotations with Entity Type Configuration when using Entity Framework Code-First.

Read More

Falafel Partners with New Venture Software to Provide Additional Custom Development Support

By | .NET, MVC, News | No Comments

Falafel is very happy to announce that we have formalized a partnership with New Venture Software, a boutique custom software development and consulting company. The partnership between Falafel and New Venture Software is built on a long history that started back in 2006. Moving forward, we are now able to extend our capabilities around .NET, MVC, WPF, HTML5, iOS development Objective C and Swift as we work side-by-side on select customer projects as needed.

Read More

Child Actions in ASP.NET MVC

By | MVC | 4 Comments

Child Actions are the action methods which can be invoked within the view. This is used to work with the data in the view, which are not related to the main action method. For example, if you want to create a data driven widget in the view using data that is not related to the main action method, you will need to use the child action method. In ASP.NET MVC any action can be used as a child action. However, to use an action only as a child action and attribute it with the ChildActionOnly. It will make sure the…

Read More

Check User exists in a Role in ASP.NET Identity 2.0

By | MVC | 8 Comments

ASP.NET MVC5 uses Identity 2.0 to manage the users and their roles. There may be scenario to check whether the currently logged in user or any user with the id exists in the given role or not, and checking can be done either in the controller class or in any other class of the application. Check for the currently logged in user In a controller you can find whether the currently logged in user exist in a role or not by using User property of the controller class. Type of the User property is IPrincipal and it has a Boolean…

Read More

Seed the database with initial Users in MVC 5

By | MVC | 9 Comments

In MVC 5 applications you may want to seed the database with initial users for various reasons. You may want default users and roles added as part of the application. In this post, we will take a look at how to  seed the database with default users. The MVC 5 application uses ASP.Net Identity 2.0 to manage users, roles and identities. ASP.Net Identity 2.0 uses the Entity framework code first approach to create a database. To seed the database, first you need to enable migration on the database. To enable migration, in the package manager console run the command enable-migrations…

Read More

Custom Action Filter in ASP.NET MVC 5

By | MVC | 8 Comments

ASP.NET MVC 5 provides five different kinds of Filters. They are as follows: Authentication [Introduced in MVC5] Authorization Action Result Exception Filters are used to inject logic at the different levels of request processing. Let us understand where at the various stages of request processing different filters get applied. Authentication filter runs before any other filter or action method Authorization filter runs after Authentication filter and before any other filter or action method Action filter runs before and after any action method Result filter runs before and after execution of any action result Exception filter runs only if action methods,…

Read More

Customize the MVC 5 Application Users’ using ASP.Net Identity 2.0

By | MVC | 15 Comments

In ASP.Net MVC 5.0, users and their roles are managed using ASP.Net Identity 2.0. By default when you create a new account email, password and confirm password are required as it’s shown below. You may come across a requirement to modify the required fields for a particular application user. For example, along with the email and password, you want to save the user’s age, country and city. In this post we will learn to modify the user information. Basically there are the three steps involved in this: Modify the ViewModel To modify the ViewModel, you should change the RegisterViewModel classin…

Read More

Three steps to use jQuery UI in ASP.NET MVC 5

By | MVC | 19 Comments

Many developers struggle to work with jQuery UI in an ASP.NET MVC application. In this post, I will show you three steps required to start working with jQuery UI in an ASP.NET MVC application. At the end of the post we will take a look at working with the autocomplete widget. The following three steps will let you work with jQuery UI in an ASP.NET MVC application: Step 1: Add the jQuery UI Reference Add the jQuery UI reference into the project using the NuGet manager. Once this is done, you should find the reference added in the Content folder…

Read More

Work with ASP.NET MVC 5 Areas from different projects

By | MVC | 14 Comments

While working on an ASP.NET MVC 5 application, I came across a requirement to use an Area from one project in another project. For example: I have a project A and a project B. I need to use an Area which is part of project B inside of project A. In this post I will discuss how this can be achieved. To start with, let us say I have an MVC project AreaDemo with the structure as follows: Right now there is one area DataAnalysis in the project. To demonstrate multiple areas, I have created multiple ActionLink in the layout…

Read More

Types of ASP.NET MVC Views

By | MVC, News | 4 Comments

I have found that many entry level developers get confused by the various kinds of Views in ASP.NET MVC Applications. In this post I am trying to clarify these different types of Views. The type of ASP.NET MVC View depends on the way the data is passed to it from the Controller. There are three ways data can be passed to Views from a Controller. They are as follows: Using ViewBag or ViewData Using object of the model which is strongly typed Using any dynamic type value On the basis of data transfer mechanism ASP.NET MVC views are categorized as…

Read More

Server Paging, Sorting, and Filtering with Kendo DataSourceRequest

By | ASP.NET, C#, Kendo UI, MVC, Telerik, Web | 13 Comments

As you would expect, the Kendo UI Grid and DataSource work extremely well together and give you paging, sorting, and filtering right out of the box.  By default, the DataSource will do all of this on the client which is fine for small sets of data, but it becomes a huge performance issue when you are dealing with thousands of records.  In this case, we need to move this work to the server. I typically do not endorse using the Kendo MVC Extensions for large applications (you get more flexibility and a cleaner architecture when you write your own Javascript),…

Read More

HTTP GET array param to ASP.NET MVC with Kendo DataSource

By | .NET, ASP.NET, JavaScript, Kendo UI, MVC | No Comments

This post is inspired by a recent conversation with one of my colleagues here. He had the following requirements: ASP.NET MVC controller (not Web API) Kendo DataSource reading with HTTP GET Controller action accepts a list of values So, something like this:

This is an awkward little corner case. Change any one of the requirements and everything will work just fine. Fresh out of the box, Web API understands sending multiple values in the query string (at least, with the right controller action method signature). MVC controllers understand arrays if they’re posted in the body of the request,…

Read More

Domain-Driven Design with ASP.NET MVC

By | Uncategorized | 2 Comments

I’ll be speaking on about Domain-Driven Design, or DDD, with ASP.NET MVC at this year’s FalafelCON event, taking place 20-21 September 2014 in San Francisco.  The event is limited to the first 200 people to register, so if you’re interested in attending, you may want to register today.  DDD is a big topic, and one I’ve been interested in for many years now.  In fact, I recently published a course on DDD Fundamentals with Julie Lerman for Pluralsight that covers the basics.  If you have a chance to watch it, let me know what you think via the course’s discussion…

Read More

Include CSS and JavaScript Resources in Sitefinity MVC Widgets

By | Sitefinity | 3 Comments

When Sitefinity added MVC in version 5.1, it was a real pleasure to create widgets the “new way” via MVC. What made it so unique is that Web Forms was still offered in the platform for developers to use as an alternative or hybrid approach, so you can mix Web Form and MVC controls on the same page. After the honeymoon stage was over, the community started to realize there was some serious limitations to the MVC implementation that made it nearly impossible to create pure MVC pages in the real world. Some examples were not being able to use your own…

Read More

Post JSON data to an MVC controller from a Kendo datasource

By | Uncategorized | 2 Comments

The default examples provided by Kendo are an excellent starting point for understanding how to implement it in your project. However, they cannot cover every scenario. One particularly common scenario is the need to send JSON data to fulfill a parameter. The dataType attribute applied to your data source or even your jQuery ajax call determines the format of the data it receives not what it sends. By default both methods send ‘post’ data to a controller as form data and ‘get’ as a querystring value. This is fine for simple requests that contain strings, integers, etc. But what if…

Read More

Embedding Sitefinity Widget MVC Views in an External Assembly

By | Sitefinity | No Comments

As we saw in the previous post, you can override the default MVC Views of the Falafel Dashboard Widgets for Sitefinity that are served from the Embedded Resources of the assembly. But how did we get the views there in the first place, and how do we serve them to the Sitefinity widgets while allowing them to be overridden with the physical files? That’s what we will be exploring today. Embedded Resources The first step is of course to embed the views inside the assembly. This is as simple as adding the views to the assembly project, and setting the…

Read More

Customizing the MVC Views of the Falafel Dashboard Widgets for Sitefinity

By | Sitefinity | No Comments

Last week, Falafel released the new Dashboard Widgets for Sitefinity, allowing you to easily add 11 new widgets to the administration dashboard for Sitefinity 6.2+. The widgets are easy to use and provide valuable information at a glance. But did you know they’re also highly customizable? Because these widgets are built with ASP.NET MVC, you can modify the View templates of each individual widget to change the layout to suit the visual needs of your site. In this post we’ll take a look at how you can achieve this. In a later post, we’ll look at the technical details that…

Read More

Get Compile-Time View Errors in ASP.NET MVC

By | ASP.NET | 2 Comments

One of the best things about using a compiled language over a scripting language is that you get compile-time checks that prevent run-time errors later. ASP.NET MVC uses a hybrid approach by default. Views are compiled at run-time, but controllers, models, and other classes are pre-compiled. MVC also allows you to create strongly-typed views, but since those views aren’t compiled until run-time, you don’t always get warned about changes to your models (like property name changes) or other errors in your view until it’s running. There’s a simple way to change this, though, by setting the views to build at…

Read More