asp.net mvc - c# MVC Nested models not returning from views -
i have mastermodel class handles lot of data partial views across shared layouts. however, when try , return part of object (or entire mastermodel) in form, such "login", no data passed controller.
here part of mastermodel:
public class mastermodel { public login login; public account account; public user user; public mastermodel() { login = new login(); account = new account(); user = new user(); } }
here part of login:
public class login { public string email {get;set;} public string passwordhash {get; private set; public string fname {get;set;} }
here part of master layout template calls partial view login:
@model models.mastermodel ... @{ html.renderpartial("../partials/_login", model.login); } ...
and here _login partial:
@model models.login <div class="login-bar"> @if (model != null && !string.isnullorwhitespace(model.fname) ) { var welcomestring = "welcome back, " + model.fname; <p>@html.actionlink(welcomestring, "overview", "account")</p> } else { using (html.beginform("login", "account", formmethod.post)) { @html.antiforgerytoken() <p> @html.label("email address:") @html.editorfor(login => login.email, new { @class = "email" }) @html.label("password:") @html.passwordfor(login => login.passwordhash) <input type="submit" value="login" class="button" /> @if (viewbag.message != null) { <shim class="red">@viewbag.message.tostring()</shim> } </p> } } </div>
here's accountcontroller httppost login too:
[httppost] [allowanonymous] [validateantiforgerytoken] public async task<actionresult> login(login login, string returnurl) { var master = new mastermodel(); // modelstate valid. login.email = "" , login.passwordhash still default if (modelstate.isvalid && (!string.isnullorempty(login.email) && !string.isnullorempty(login.passwordhash))) { var user = await usermanager.findasync(login.email, login.passwordhash); if (user != null) { await signinasync(user, true); master.user = user; return redirecttoaction("overview", "account", master); } } return view(master); }
i've tried passing entire mastermodel partial view instead (also changing @model use models.mastermodel) whilst accessing login property mastermodel.login.email, etc, no avail.
it's got pretty simple i'm missing binding on property names, i'm starting go code blind now!
any ideas?
[update] - added accountcontroller
everything seems ok.. might try renaming parameter in login action besides login
public async task<actionresult> login(login model, string returnurl)
and maybe same in partial
@html.editorfor(model => model.email, new { @class = "email" })
Comments
Post a Comment