Reputation: 3408
I'm trying to create a plugin for nopCommerce v2.20 that allows the user to request a quote for goods and services by describing the requirements and attaching any relevant documents.
I have started by using http://blog.csharpwebdeveloper.com/2011/09/10/writing-a-plugin-for-nopcommerce-2-x/ as a guide, this has been very good so far. My project is almost identical to the one in the blog post so I'll only add code snippets as I think they are required, so please ask me to expand and provide details if I have left anything important out.
Now I want to add a facility to upload multiple files using uploadify and have decided based on the existing code that I should create an EditorTemplate for attachments.
My problem is I can't work out how to setup my template in a way that can be located by the MVC framework when I use the following line of code to get the template.
@Html.EditorFor(m => m.Attachment)
In my model I’m using the UIHintAttribute("Attachments") on the Attachment property to identify the template with no noticeable effect.
I have created a folder below the "Views" folder called "EditorTemplates" and added a file called "Attachments.cshtml" with the build action set to "Embedded Resource", contents below:
@model int
@using Nop.Core;
@{
var randomNumber = CommonHelper.GenerateRandomInteger();
var clientId = "download" + randomNumber;
var downloadService = EngineContext.Current.Resolve();
var download = downloadService.GetDownloadById(Model);
}
<div>This is a download control @string.Format("randomNumber = {0}, clientId = {1}, download = {2}", randomNumber, clientId, download);</div>
I intend to implement the template once I can get the MVC framework to resolve its location.
So is it possible to have an editor template in a plugin (a separate class library from the main project) and if so what do I need to do to enable the MVC framework to resolve my template location?
I'd also like to add I'm quite new to MVC, Razor, and nopCommerce, sorry in advance if I missed something obvious.
As a side, could you suggest a better title for my question as stackoverflow tells me that it appears subjective?
thanks
Upvotes: 2
Views: 1326
Reputation: 4993
If you are trying to supply an editor template without pre-compilation (which is probably the best way until you get into some more advanced scenarios) you will want to set the BuildAction as "Content" - not "EmbeddedResource".
Also, make sure your editor template is in one of the following directory structures (you mentioned it was under "Views" which is incorrect):
If you do want to embed the templates as part of a separate library, I suggest you look at this post from Chris Van De Steeg.
Upvotes: 3