A Simple Sitecore + Bootstrap + MVC + Solr Example Project

I recently had the need to develop an example project in Sitecore with the following requirements:

Build a mini CRM in Sitecore using MVC with the following features:
    a. A page where a user can add contact details – Name, email, phone and address
    b. A listing page with search capabilities (search by email, first name)
    c. Ability to edit and delete users
    d. A decent user interface

Soooooo, I put this project together in a hurry and demonstrated it to my client. And now that I have no need for it anymore, why not share it on the blog, right? Cut me a little slack on this one - I did the whole thing in about 4 hours, so i can't vouch for coolness or completeness.

I developed this on Sitecore 8.2 Update 2, but it should work on any Sitecore version 7.5 or later. The requirements called for search capability, so I chose to go with Solr. You could just as easily use Lucene or Azure Search or even something more sophisticated like Coveo for Sitecore if you were so inclined. I am storing the user records as bucketed items in Sitecore. The requirement for "a decent user interface" is accomplished with Bootstrap and MVC Razor views.

Prerequisites:

  1. You will need to install Sitecore
  2. You will need to install Solr
  3. You will need Visual Studio 2017 or later

Instructions:

  1. Download the full Mini CRM solution here: MiniCrm.zip (362.64 kb).
  2. Unzip the solution somewhere, and open it in Visual Studio.



  3. Restore all the Nuget packages.
  4. Add references to your Sitecore assemblies:
    - Sitecore.ContentSearch.dll
    - Sitecore.ContentSearch.Linq.dll
    - Sitecore.Kernel.dll
    - Sitecore.Mvc.dll
  5. Take a look at this config file: /app_config/include/MiniCrmIndex.config. As you can see, you need to create a new Solr core named "mini_crm_index_master". Here are some tips on how to do it.
  6. Create a publish profile in Visual Studio that points to your Sitecore instance.
  7. Publish the solution. This will publish the following assets to your website (Most of these files are the ones that come with a standard Visual Studio web application):
    /App_Config/include/MiniCrmIndex.config
    /bin/MiniCrm.dll
    /content/bootstrap.css
    /content/bootstrap.min.css
    /content/site.css
    /fonts/glyphicons-halflings-regular.eot
    /fonts/glyphicons-halflings-regular.svg
    /fonts/glyphicons-halflings-regular.ttf
    /fonts/glyphicons-halflings-regular.woff
    /scripts/bootstrap.js
    /scripts/bootstrap.min.js
    /scripts/jquery-1.10.2.intellisense.js
    /scripts/jquery-1.10.2.js
    /scripts/jquery-1.10.2.min.js
    /scripts/jquery-1.10.2.min.map
    /scripts/modernizr-2.6.2.js
    /views/MiniCrm/UserEdit.cshtml
    /views/MiniCrm/UserList.cshtml
    /views/MiniCrm/web.config
    /views/shared/_Layout.cshtml
    /views/_ViewStart.cshtml



  8. Now it's time for some Sitecore work. Log in to your Sitecore as an Admin, and install this package 

    MiniCrm Sitecore Items-1.0.zip (41.30 kb). This will install the following items:

    • /sitecore/templates/User (this is the User template)
    • /sitecore/layout/Renderings/User List Rendering (this is a Controller Rendering for the user list method)
    • /sitecore/layout/Renderings/User Edit Rendering (this is a Controller Rendering for the user edit method)
    • /sitecore/layout/Renderings/User List Rendering (this is a Controller Rendering for the user delete method)
    • /sitecore/content/Users (this is the bucket folder to store User items)

  9. Next, we'll set up the presentation items. Add three new items to your content tree: "UserList", "UserEdit" and "UserDelete".
  10. Configure the presentation details for each item (here's an example for the UserList item):



  11. At this point you're ready to run your new application! Here are some screen shots:


So there you have it! I hope this example is helpful to someone out there in Sitecore land. If I had more time to work on this I certainly would have included things like unit tests, better error handling for edge cases, more functionality on the form, like sorting, etc. But this gives you the basic idea of how to do MVC in Sitecore.

Enjoy!

~David

Add comment

Loading