ASP.NET MVC3 Html.EditorFor() problem

i try to bind data to model with Html.EditorFor() helper and submit, but model come to controller is null.

Here is 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 is 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 is generate like this:

<input id="UserName_UserName" name="UserName.UserName" type="text" value="qwerty" />
<input id="Password_Password" name="Password.Password" type="password" />

it seems like error in html-generated code, it should be id="someid" value="somevalue", but not id="someid_someid" value="somevalue.somevalue"

Answers


Since you're just using textboxes you could always use the following

@using (Html.BeginForm()) {
    @Html.TextBoxFor(m => m.UserName);
    @Html.PasswordFor(m => m.Password);
   <input type="submit" value="LogOn" />
}

Otherwise it might depend on custom templates that you've created.


Need Your Help

Javascript popupWindow and fill some web form field

javascript webforms fill popupwindow

I'm trying to write a script to popup a web form and then auto fill the form field with some data.

Alterning a table that has spaces in its name

mysql sql

I want to add 3 columns. There are two things that I dont know, one is how to specify a default value for each column, and then next is how to alter a table that has got spaces:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.