Search code examples
sitefinitysitefinity-mvc

How to integrate my code into a sitefinity project


We have a sitefinity Customer Portal. Now we need to add MVC pages to it. I understand how to add a page, and how to drag e.g. a list to the page's content. But I don't understand how I can create a controller and other c# code to populate the list and do other custom things. We cannot open the project in Visual Studio, and we have no access to the existing code.


Solution

  • First of all, you must sure your project run success on your local. You can check it by login to back end page.

    Then you can create the MVC component like this: (you should create all of this in root/MVC folder)

    Create controller first:

    [ControllerToolboxItem(Name = "ImportCSV", Title = "ImportCSV", SectionName = "ImportCSV")]
    public class ImportCSVController : Controller
    {
        // GET: ImportCSV
        public ActionResult Index()
        {
            return View();
        }
    }
    

    SectionName is title of content group for you custom Title is the title of component Name is used for code behind

    Then you can create the views to show in page: (you have to create the views in MVC/Views/ImportCSV, sitefinity will recognize folder name to map in BE)

    <h2>Upload File</h2>
    <div class="form-group">
    <input type="file" id="dataFile" name="upload" />
    </div>
    <div class="form-group">
        <a onclick="upload()" class="button" id="btnupload">Upload</a>
    </div>