Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig100 1136 posts 2522 karma points c-trib
    Apr 19, 2014 @ 21:49
    Craig100
    0

    MVC Forms

    This document could be helpful if it told you where to put the parts it describes. http://our.umbraco.org/documentation/Reference/Templating/Mvc/forms

    Could someone tell me where to create the ViewModel and the SurfaceController. I guess the PartialView goes in the /PartialView directory? Or do they have to be in a separate project, built and have the dll dropped into Umbraco's bin folder?

    Too many of the docs assume expert knowledge of this stuff, which is fine for a "reference" but not for a "guide". People generally need "guides" as this works as a reference as well.

    Thanks

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Apr 20, 2014 @ 22:01
    Andy Butland
    0

    Hi Craig

    View models and surface controllers will be compiled code, so really you can put them wherever suits you best.  Convention for an MVC project though is to put controllers in a folder called "Controllers" and view models in one called "Models".  If you prefer though you can certainly put them in a seperate project and reference that from your web appplication.

    Andy

  • Craig100 1136 posts 2522 karma points c-trib
    Apr 20, 2014 @ 22:14
    Craig100
    0

    Hi Andy,

    So if you add the Controllers and Models directories to the Umbraco install then you'd have to "build" the whole thing?  I'm guessing if you put them in a seperate project then you'd lose the ability to code with @Model.Content...etc.?  I want to add dropdowns to my forms populated from Umbraco content and am not at all sure where to place the files, hence this question.

    Craig

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Apr 21, 2014 @ 14:56
    Andy Butland
    0

    Yes, that's right.  If you really want or need to avoid Visual Studio, you can put them in the App_Code folder - and they won't then need to be compiled.  But really once you get into creating your own controllers and view models I'd suggest you'd want to make use of the benefits VS.Net provides.

    A seperate project doesn't prevent you using the @Model. syntax though.  So long as the project with the controller classes in is referenced from your web application project that'll work fine.

    Andy

  • Craig100 1136 posts 2522 karma points c-trib
    Apr 21, 2014 @ 15:04
    Craig100
    0

    Well I had code in a seperate project and couldn't access the Umbraco Model at all. I put a seperate question on OUR about it, asking what are the references you need, but so far not had a *successful* answer.

    Thanks for your repy, it's been helpful.

    Craig

  • Charles Afford 1163 posts 1709 karma points
    Apr 21, 2014 @ 21:20
    Charles Afford
    0

    Hi you can look at: http://www.charlesafford.com/setting-up-and-using-your-first-surface-controller.aspx

    That will tell you basically how to create a surface controller and a view with a partial view and model.

     

    Basically:

     

    ViewModel is a c# class with public properties and other methods.  

    public class MyViewModel

    {

    public string FirstName{get;set;}

    }

     

    You can use this in a partial view using @model directive

    @model MyViewModel 

    @{

    <h1>@Model.FirstName</h1>

    }

     

    Surface controller is a class (c#) that implments SurfaceController and has a public method that returns and ActionResult

    public mysurfacecontroller : SurfaceController

    {

    public ActionResult MyActionResult(myViewModel viewModel)

    {

    return PartialView("your partial view)

    }

    }

     

    Hope this helps :).

    Charlie.

Please Sign in or register to post replies

Write your reply to:

Draft