Hi, I wanted to send the model to the controller, unfortunately I get the error: "Can not bind source type Umbraco.Web.Models.RenderModel is model type Umbraco12.Models.Home."
ViewModel:
namespace Umbraco12.Models
{
public class Home : RenderModel
{
public Home(IPublishedContent content, CultureInfo culture) : base(content, culture)
{
}
public string Topic { get; set; }
}
}
Controller:
public class HomeController : Umbraco.Web.Mvc.RenderMvcController
{
// GET: Home
[HttpGet]
public ActionResult Home(RenderModel model)
{
var home = new Home(model.Content, model.CurrentCulture);
//Do some stuff here, then return the base method
return View("Home", home);
}
[HttpPost]
public ActionResult HomePost(Home model)
{
//Do some stuff here, then return the base method
return View("Home", model);
}
}
I used the Surface Controller and now I have an error
"No parameterless constructor defined for this object"
Controller:
public class HomeSurController : SurfaceController
{
// GET: HomeSur
[HttpPost]
public ActionResult HomePost(Home model)
{
//Do some stuff here, then return the base method
return View("Home", model);
}
}
Umbraco HttpPost error
Hi, I wanted to send the model to the controller, unfortunately I get the error: "Can not bind source type Umbraco.Web.Models.RenderModel is model type Umbraco12.Models.Home."
ViewModel:
Controller:
View:
If you want to post data back to the server, you should be using a surface controller, there is a tutorial here:
https://our.umbraco.com/Documentation/Reference/Templating/Mvc/Forms/tutorial-sensitive-data
I used the Surface Controller and now I have an error "No parameterless constructor defined for this object"
Controller:
View
Hello Niker,
are you sure you are passing a model to your action?
I assume this error occures because you expect a homemodel as parameter but it's not beeing received.
Please try passing an id instead and use the id to get the model in the HomePost Action to see if this causes the problem.
Regards, Jonathan
I do not understand what ID and where?
Ok, rozwiązałem problem. Wystarczyło dodać taki konstruktor w viewmodelu Home:
is working on a reply...