Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

Your assistance and wisdom regarding this matter is truly appreciated.

share|improve this question

1 Answer 1

You can access SharePoint data using an App, you just cannot use SharePoint Server-Side Object Model code. But you could easily access and manipulate data using the SharePoint web services or client object model.

If you really want to use Razor within SharePoint, it looks like all you need to do is use NuGet to add Razor to your project. You then build your model as expected and your .cshtml as usual. Upload the .cshtml to a document library and it runs as it would in an MVC application. But I am not certain this is going to work in a VisualWeb part.

http://naveengopisetty.wordpress.com/2012/08/05/razor-engine-in-sharepoint-2013/

http://nickgrattan.wordpress.com/2012/12/08/developers-toolset-for-sp2013-add-mvc-and-mix-in-razor/

share|improve this answer
    
alright I will give that a shot, it wouldn't work in a VisualWebPart because it has aspx web forms... okay that makes sense. I'll try this and will accept this if I succeed –  MyName May 6 '13 at 21:25
    
You should do a blog post on the topic if you do get it working! I would be interested in reading about the process. –  Robert Kaucher May 7 '13 at 13:01
    
Alright, will do –  MyName May 7 '13 at 17:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.