I've trieda version of that.. basically my surface controller looks like this
public ActionResult RegisterPost(RegistrationViewModel tModel)
{
if (ModelState.IsValid)
{
// Send email
TempData["success"] = true;
var memberService = Services.MemberService;
//Get values from DB
if (CheckAccountExists(tModel))
{
//add user to members
string fullName = GetFullName(tModel.AccountNumber);
if (!CheckMemberExists(tModel))
{
var member = memberService.CreateMember(tModel.EmailAddress, tModel.EmailAddress, fullName,
"RegisteredUser");
member.SetValue("memberGuid", member.Key);
member.IsApproved = true;
// Don't forget to save all these things
memberService.Save(member);
//do other database actions
AddMembertoDatabase(tModel, member.Key);
}
else
{
ModelState.AddModelError("", "member already exists. Aborting!");
return CurrentUmbracoPage();
}
}
else
{
ModelState.AddModelError("",
tModel.EmailAddress +
":Account Number Does Not match our records. Aborting!");
return CurrentUmbracoPage();
}
return RedirectToCurrentUmbracoPage();
// return Redirect("ExtendedRegistration");
}
else
{
ModelState.AddModelError("",
"There was an issue posting the variables!");
}
}
Aha its about the way I was setting my @inherits
@inherits sets the view base class
you need to set the model type
so i changed my code to make sure the model was and is coming through properly in the p artial and posting to the controller.. I'll update this a bit later
Form losing values between post and Surfacecontroller
I have a loevly view and a with the following form
@using(Html.BeginUmbracoForm("CreateRegistration", "RegisterSurface")) {
@Html.ValidationSummary(true)
</div>
<div class="editor-label">
@Html.LabelFor(m => rvmodel.AccountNumber)
@Html.TextBoxFor(m => rvmodel.AccountNumber)
@Html.ValidationMessageFor(m => rvmodel.AccountNumber)
</div>
<input type="submit" />
}
I output a number of fields
but when I post to my surface controller I lose my data
The controller is being accessed fine and tries to process everything
public class RegisterSurfaceController: SurfaceController
{
[HttpPost]
[ActionName("CreateRegistration")]
public ActionResult RegisterPost(RegistrationViewModel tModel)
{
tModel is however empty
Does Stuff in here
}
}
but since tmodel is empty I have nothing to process
anyideas
Ravi, see my recent post about why I think this is happening and my current workaround:
http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/59655-Umbraco-7-SurfaceController-Persist-ModelStateModel
Deleted. See post from my first response. Use return
CurrentUmbracoPage()
instead of returnRedirectToCurrentUmbracoPage()
.I've trieda version of that.. basically my surface controller looks like this
However I just get the empty TModel..
Aha its about the way I was setting my @inherits @inherits sets the view base class you need to set the model type
so i changed my code to make sure the model was and is coming through properly in the p artial and posting to the controller.. I'll update this a bit later
I found that my issue was related to what i had in the inherits in my template page and in the subsequent partial page
In my template page I was originally passing a different model @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
and this was interfering with the model i called in the partial
I now have
and in my surface controller I added a child action and that seemed to sort me out
is working on a reply...