post - MVC Model not posting -


when click login button never model posted server. if accept formcollection see values. how can make automatically bind model instead of searching form collection?

from have read there few common problems this:
1 - view not specify model using (@model myapp.models.name)
2 - model not use properties
3 - of required fields missing

controller

[httpget] public actionresult password() {     return view(new authviewmodel()); }  [httppost] public actionresult password(authviewmodel password) {     if (password == null || string.isnullorempty(password.password))     {         viewbag.error = constants.errormessages.userpassword_passblank;         return view(new authviewmodel());     }      //success     return redirect("/"); } 

model

public class authviewmodel {     public string password { get; set; } } 

view

@model mvcapplication1.models.authviewmodel @{     viewbag.title = "password"; }  <h2>password</h2> @using (html.beginform()) {     <div>@html.textboxfor(m => m.password,new{placeholder="password",type="password",autofocus=""})</div>     <div><button id="btnlogin" type="submit">login</button></div>     <div class="error">@viewbag.error</div> } 

not sure why dan's answer isn't working without trying it, looks should. took @ of code login form, similar yours. here's mine :

public class signinmodel {     [required]     [display(name = "enter email address")]     public string email { get; set; }      [required]     [datatype(datatype.password)]     [display(name = "enter password")]     public string password { get; set; }      [display(name = "remember me?")]     public bool rememberme { get; set; } } 

the main difference see mine has [datatype(datatype.password)] attribute on password. not sure if makes difference though.

the other thing noticed different in form specify form method post. i've used editorfor() helper instead of textbox or password:

@using (html.beginform("signin", "account", "post")) {     <div class="form-field">         @html.labelfor(x => x.email)         @html.editorfor(m => m.email)     </div>     <div class="form-field">         @html.labelfor(x => x.password)         @html.editorfor(m => m.password)     </div>     <div class="form-remember">         @html.checkboxfor(m => m.rememberme)         @html.labelfor(x => x.rememberme)     </div>     <button type="submit">         sign in</button> } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -