Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 15:37
    Ismail Mayat
    0

    Current page in view

    So I have a view its for my surface controller code looks like

    @using TEF.Common.Model

    @using TEF.Web.Controllers.SurfaceControllers

    @using TEF.Web.Models

    @model SearchFormModel

    <div id="leftCol">

     

        @using(Html.BeginUmbracoForm<SearchFormSurfaceController>("HandleSearchForm") )

        {

        }

    In the view how do i get the current page? I cannot do @Current intellisense gives red warning also cannot do Model.Content get error CS1061: 'TEF.Web.Models.SearchFormModel' does not contain a definition for 'Content' and no extension method 'Content'

    Any ideas

    Regards

    Ismail

  • antao 81 posts 371 karma points
    Jul 12, 2013 @ 15:40
    antao
    0

    Hey Ismail, shouldn't you be inheriting from the UmbracoTemplatePage?

  • Dirk De Grave 4539 posts 6017 karma points MVP 3x admin c-trib
    Jul 12, 2013 @ 15:41
    Dirk De Grave
    100

    if you inherit your SearchFormModel from RenderModel and use @inherits UmbracoViewPage<SearchFormModel>, you should be fine as you'll be able to use the umbraco view infrastructure.

     

    /Dirk

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 15:43
    Ismail Mayat
    0

    Then my model code breaks 

    @model SearchFormModel

     @Html.DropDownListFor(model => model.Weight.Keys,

                                          new SelectList(

                                              Model.Weight, 

                                              "Key", 

                                              "Value"),"Please select")

    Regards

    Ismail

  • Dirk De Grave 4539 posts 6017 karma points MVP 3x admin c-trib
    Jul 12, 2013 @ 15:47
    Dirk De Grave
    1

    Ismael, you don't need both @inherits and @model, only the first is required...

    /Dirk

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 15:54
    Ismail Mayat
    0

    Dirk,

    So my model looks like 

     public class SearchFormModel : RenderModel 

    however in my class I have a constructor which fills some values on the public properties. When I compile i get error Error12'Umbraco.Web.Models.RenderModel' does not contain a constructor that takes 0 arguments

    I wants IPublsihedContent no doubt the current page so what do i pass in there.  Btw in the view i can now get Model.Content so on the right track.

    Regards

    Ismail

  • Comment author was deleted

    Jul 12, 2013 @ 15:56

    Think Dirk has the answer.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Xml;

    using Umbraco.Core.Models;
    using Umbraco.Web.Models;
    using umbraco.BusinessLogic;

    namespace CustomControllers
    {
    public class Model1 : RenderModel
    {


    //put everything in here or create a chain of inheritance
    }

    }

     

    @inherits UmbracoViewPage<Model1>

     

    I just learned MVC this week so take it FWIW :)

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 15:58
    Ismail Mayat
    0

    Kevin,

    Hah im doing same this week finally taking the plunge. So I have the above but my model has a constructor unless I am doing it wrong and should hydrate the model differently?

    Regards

    Ismail

  • Comment author was deleted

    Jul 12, 2013 @ 15:58

    Constructor

            public Model1(IPublishedContent content)
    : base(content)
    {

    }

     

  • Comment author was deleted

    Jul 12, 2013 @ 16:01

    Then later, override the controllers

     

    namespace CustomControllers
    {
    public class CustomController: RenderMvcController
    {
    public override ActionResult Index(RenderModel model)
    {
    Model1 newModel = new Model1(CurrentPage);


    return CurrentTemplate(newModel);
    }
    }

    public class Template1Controller : CustomController
    {
    }
    }
  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 16:01
    Ismail Mayat
    0

    Ok Kevin,

    Nearly there did what you said however know in my controller i get error

            public ActionResult RenderSearchForm(){

    return PartialView("SearchForm", new SearchFormModel());

    }

    its expecting IPublishedContent in the constructor so how i get that in the surfacecontroller?

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 16:05
    Ismail Mayat
    0

    Woohoo,

    Fixed. I updated my controller to

            public ActionResult RenderSearchForm(){

    return PartialView("SearchForm", new SearchFormModel(CurrentPage));

    }

    Many thanks to all. Best community ever #fact I still have outstanding questions on another cms forum and still no reply weeks later. Here I get 3 peeps helping on one topic so spoilt lol!!!

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 16:06
    Ismail Mayat
    0

    Arghgghgh. Ok so now when i submit the form i get 

    No parameterless constructor defined for this object

     

    Need to update may be in one more place?

  • Comment author was deleted

    Jul 12, 2013 @ 16:13

    Sounds like wherever you are doint an inherit, you are missing a constructor altogether.  I haven't done any partials yet so I'm gonna have to defer.

  • Dirk De Grave 4539 posts 6017 karma points MVP 3x admin c-trib
    Jul 12, 2013 @ 16:15
    Dirk De Grave
    1

    Sample code to use with your model

    public class DocumentTemplateConfirmationViewModel : RenderModel
    {
    public DocumentTemplateConfirmationViewModel() : this(new UmbracoHelper(UmbracoContext.Current).TypedContent(UmbracoContext.Current.PageId)) { }
    public DocumentTemplateConfirmationViewModel(IPublishedContent content) : base(content) { }
    public DocumentTemplate DocumentTemplate { get; set; }
    public DocumentTemplateRole Role { get; set; }
    public RegistrationViewModel RegistrationViewModel { get; set; }
    }

     

    should get you started!

     

     

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Jul 12, 2013 @ 16:26
    Ismail Mayat
    0

    Dirk,

    Awesome many thanks all working now. 

    Regards

    Ismail

  • Dirk De Grave 4539 posts 6017 karma points MVP 3x admin c-trib
    Jul 12, 2013 @ 16:30
    Dirk De Grave
    0

    Cool, glad I could be of help just before the weekend! Have a good one!

     

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft