Using the razor engine in SharePoint 2013 Visual Web Part
Asked Answered
D

3

6

I'm trying to make use of the razor engine in a SharePoint 2013 Web Part. This, I read, shouldn't be too difficult since SharePoint 2013 Visual Web Parts can be built using .NET Framework 4.0

I'm simply not sure of where to begin to do this. I've seen an article on uploading the .cshtml file onto a document library and referencing the document library in the Web Part, but it is a bit unclear.

Does anyone have an idea of how I can start? Or point me to a step-by-step guide to achieve what I am after.

What my end goal is: Take a piece of an MVC application, customize it and make it a Web Part. I need to be able to modify or access SharePoint content on that site which is why I cannot use an App Part.

Danyel answered 6/5, 2013 at 20:20 Comment(0)
O
1

Okay.

First install the Office Development Templates from

http://www.microsoft.com/visualstudio/eng/office-dev-tools-for-visual-studio

This will give you the following template selection on reopening Studio

VS Office and Sharepoint Templates

Then navigate to wherever EwsManagedApi32.msi is and enter the following command in an elevated prompt -

EwsManagedApi32.msi addlocal="ExchangeWebServicesApi_Feature,ExchangeWebServicesApi_Gac"

Now your templates are usable and the one you want is "VS2012 Web Part".

Now, by default this will add an ASP.NET project, which is not what you want, so manually delete the ASP.NET project, add an MVC one, highlight the SharePoint project in Solution Explorer, hit F4, and select the MVC project in the "Web Project" dropdown at the bottom of the properties.

And there you go. One controller per web part, sorted.

Optimist answered 1/8, 2013 at 20:56 Comment(1)
I should note further that you need to be running your development environment on a machine or VM whic has Sharepoint installed. It's ugly, but there it is.Optimist
D
0

I am sharing link SharePoint MVC webpart that uses Knock out framework using MVC for SharePoint. It has step by step instructions which might help you.

Doorframe answered 7/5, 2013 at 7:49 Comment(1)
The question was about ASP.Net MVC - That article doesn't use ASP.Net MVC at all; it uses Knockout and a UserControlGreenburg
P
0

Hope this will be a good starting point http://www.codeproject.com/Tips/739445/SharePoint-Razor-View-WebPart

Paste answered 6/3, 2014 at 20:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.