Hi
Can't figure this out - hence the post :)
I am using V7.8.1 so models builder is also installed and enabled. I have changed the mode to AppData to allow me to extend the models. This is all good I have a HomeTemp partial class
{
public string PetName
{
get; set;
}
public string CallerName
{
get; set;
}
}
Controller
public class HomeTempSurfaceController : SurfaceController
{
public ActionResult ShowForm(HomeTemp homeTemp)
{
homeTemp.PetName = "Fido";
return PartialView(viewName: "HomeTempPartial", model: homeTemp);
}
public ActionResult HandleFormPost(string submitButton, HomeTemp homeTemp)
{
Session["CallerName"] = homeTemp.CallerName;
Session["PetName"] = homeTemp.PetName;
return Redirect(homeTemp.Start.Url);
}
}
The page loads correctly with the textbox field PetName prepopulated with 'Fido'. Which can be edited and caller name can be added.
The submit is posting the model to the controller but the model has null values for PetName and CallerName.
Saving input to session
Hi Can't figure this out - hence the post :) I am using V7.8.1 so models builder is also installed and enabled. I have changed the mode to AppData to allow me to extend the models. This is all good I have a HomeTemp partial class
Controller
And a partial view
The page loads correctly with the textbox field PetName prepopulated with 'Fido'. Which can be edited and caller name can be added. The submit is posting the model to the controller but the model has null values for PetName and CallerName.
Can anyone see what I'm doing wrong? Thanks Alan
Hi Alan
What if you remove "submitButton" param from the action? Like that:
Alex
Hi Alex
Thanks for trying, took it out incase it was causing something wierd but still the same. Cheers Alan
Hi Alan,
I wonder if it's because you're using EditorFor which will generate html for all fields in the model but you're specifying them individually.
Change these to @Html.TextBoxFor and see if that solves it.
HTH Steve
Hi Steve
Thanks, I'd started with .TextBoxFor and then found a post explaining EditorFor gives more functionality.
Cheers Alan
Did that fix it?
Hi Steve
Unfortunatly not but thanks.
Alan
Hi I've got round it by using
and
far from ideal so if any kind person out there sees where I'm going wrong and can post a proper slution it would be appreciated.
Thanks for reading this far and good luck.
Thanks, Alan, for sharing the solution with our community
Wouldn’t mark it as a solution. There most be a way of using passing the edited data within the model. I’m missing something stupid. Cheers Alex Alan
Hi Alan
Sorry for marking the topic as solved.
This code works for me:
Veiw:
Controller:
/Alex
Thanks again Alex. Issue appears to be related to the Models Builder which is now rolled into the Umbraco release, or to be more precise my use of models along with the builders generated models. If anyone else having this problem the solution is best explained at https://stackoverflow.com/questions/41913529/how-to-post-a-custom-model-to-a-controller-in-umbraco-7-5-8 Thanks to Alex and Steve for replying.
is working on a reply...