Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
public string CallerName
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;
And a partial view
<label for="CallerName">Caller Name:</label>@Html.EditorFor(x => x.CallerName)
<label for="PetName">Pet Name:</label>@Html.EditorFor(x => x.PetName)
<input type="submit" value="Submit" />
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?
What if you remove "submitButton" param from the action? Like that:
public ActionResult HandleFormPost(HomeTemp homeTemp)
Thanks for trying, took it out incase it was causing something wierd but still the same.
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.
Thanks, I'd started with .TextBoxFor and then found a post explaining EditorFor gives more functionality.
Did that fix it?
Unfortunatly not but thanks.
I've got round it by using
@using (Html.BeginForm("HandleFormPost", "HomeTempSurface"))
public ActionResult HandleFormPost( FormCollection homeTemp)
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
Wouldnt mark it as a solution. There most be a way of using passing the edited data within the model. Im missing something stupid.
Sorry for marking the topic as solved.
This code works for me:
@Html.LabelFor(m => registerModel.Name)
@Html.TextBoxFor(m => registerModel.Name)
public ActionResult HandleRegisterMember([Bind(Prefix = "registerModel")]RegisterModel model)
Thanks for this, I'm on a different project today and away on holiday tomorrow for a week. Will try it out when I get back.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted