I am working on NopCommerce v3.80. By Default the login and register views are different. I needed to merge them without changing much of the code, so I called @{ RenderAction("Register"); } inside Login.cshtml.
I also removed the layout (Layout = "~/Views/Shared/_ColumnsOne.cshtml";) from Register view.
the problem is when a validation error like 'Email Id already Exists!' comes, it goes to the register view. I need to show the validation or error message on the login view. but the login view accepts only Login Model.
Please see my code :
Register.cshtml
@model RegisterModel
@using Nop.Web.Models.Customer;
@{
//Layout = "~/Views/Shared/_ColumnsOne.cshtml";
}
<!-- Registeration fields -->
Login.cshtml
@model LoginModel
@using Nop.Web.Models.Customer;
@{
Layout = "~/Views/Shared/_ColumnsOneTT.cshtml";
}
@using (Html.BeginForm("Register", "Customer", FormMethod.Post)){
<div>
@{
Html.RenderAction("Register");
}
<input type="submit" value="Submit"/>
}
CustomerController.cs - Register Method
public ActionResult Register(RegisterModel model){
// Lot of code
if (success){
// lot of code
return RedirectToRoute("RegisterResult");
}
foreach (var error in registrationResult.Errors)
ModelState.AddModelError("", error);
PrepareCustomerRegisterModel(model, true, customerAttributesXml);
return View(model);
}
UPDATE : I checked how to work with two forms in a single view but it won't help me as I can not go with new model creation option.
UPDATE 2: I also tried with the new model creation option which covers the login and register models but I am still getting the same result.
Thank you all for your efforts.I had to create new model and wrap the two models Register and Login inside that.
it looks like how to work with two forms in a single view helped me a lot.
However, I am posting complete solution for a newbie.
CustomerController:
Loading the page
Login POST :
Register:
Register POST :
Then created two partial Views -
_LoginModel.cshtmland_registerModel.cshtml. In the views I added only one extra line_LoginModel.cshtml:
_RegisterModel.cshtml
and finally, Login page
Login.cshtml
replaced register button (left panel with )
and login form with