tags:

views:

26

answers:

1

Im trying to exclude a required property(Password) so the modelstate dont validate that property, but for some reason it still validate even when i try to exclude it.

Controller:

    [Authorize, AcceptVerbs(HttpVerbs.Post)]
    public ActionResult _Edit(int id, [Bind(Exclude = "Password")]FormCollection collection)
    {
        var user = Proxy.GetUser(id);

        TryUpdateModel(user, null, null, new[]{"Password"});

        if(!ModelState.IsValid)
            return PartialView(user);

        Proxy.UpdateUser(user);
    }

View:

   ...
   <tr>
       <td class="label">
           <label class="row_description" for="Password"><%= S._("Password")%></label>
       </td>
       <td>
           <%= Html.Password("Password", null, new { @class = "row_input" })%>
           <%= Html.ValidationMessage("Password", "*")%>
       </td>
   </tr>

User(using dataannotation):

[Required]
public string Password { get; set; }

Im using VS2008, MVC2, firefox

Maybe im just tired and can't see it. Any help is appreciated

A: 

Maybe you should replace

TryUpdateModel(user, null, null, new[]{"Password"});

with

TryUpdateModel(user, null, null, new string[] {"Password"});

Because it might be confusing which overload for TryUpdateModel is using. Just saying...

Francisco
Thx for response, but i think my problem is related to me using same model for create and edit. I want password to be required when creating but not when editing. White/black list apparently does not have anything to do with modelstate being valid :D
larole