c# - ASP.NET MVC3 Html.EditorFor() problem -
i try bind data model html.editorfor() helper , submit, model come controller null.
here code of model:
public class logonmodel { [localizedrequired] [localizeddisplayname("user name")] public string username { get; set; } [localizedrequired] [datatype(datatype.password)] [localizeddisplayname("password")] public string password { get; set; } [localizeddisplayname("remember me")] public bool rememberme { get; set; } }
this cshtml:
@model models.logonmodel { view.title = "log on"; } @using (html.beginform()) { @html.editorfor(m => m.username); @html.editorfor(m => m.password); <input type="submit" value="logon" /> }
and html code generate this:
<input id="username_username" name="username.username" type="text" value="qwerty" /> <input id="password_password" name="password.password" type="password" />
it seems error in html-generated code, should id="someid" value="somevalue", not id="someid_someid" value="somevalue.somevalue"
since you're using textboxes use following
@using (html.beginform()) { @html.textboxfor(m => m.username); @html.passwordfor(m => m.password); <input type="submit" value="logon" /> }
otherwise might depend on custom templates you've created.
Comments
Post a Comment