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'
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.
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.
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?
namespace CustomControllers { public class CustomController: RenderMvcController { public override ActionResult Index(RenderModel model) { Model1 newModel = new Model1(CurrentPage);
return CurrentTemplate(newModel); } }
public class Template1Controller : CustomController { } }
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!!!
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
Hey Ismail, shouldn't you be inheriting from the UmbracoTemplatePage?
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
Then my model code breaks
@model SearchFormModel
@Html.DropDownListFor(model => model.Weight.Keys,
new SelectList(
Model.Weight,
"Key",
"Value"),"Please select")
Regards
Ismail
Ismael, you don't need both @inherits and @model, only the first is required...
/Dirk
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
Think Dirk has the answer.
I just learned MVC this week so take it FWIW :)
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
Constructor
Comment author was deleted
Then later, override the controllers
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
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
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
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.
Sample code to use with your model
should get you started!
Dirk,
Awesome many thanks all working now.
Regards
Ismail
Cool, glad I could be of help just before the weekend! Have a good one!
/Dirk
is working on a reply...