tags:

views:

20

answers:

1

When I login I enter my user name and password. On a different create view these values also populate the email address and the password fields. Why is this, and what can I do to stop it?

The next 2 markups are my login view and my create view

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ITOC.WebUI.Models.LogOnModel>" %>

<asp:Content ID="loginTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Log On
</asp:Content>

<asp:Content ID="loginContent" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Log On</h2>
    <p>
        Please enter your username and password.
    </p>
    <% using (Html.BeginForm()) { %>
        <%: Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") %>
        <div>
            <fieldset>
                <legend>Account Information</legend>

                <div class="editor-label">
                    <%: Html.LabelFor(m => m.UserName) %>
                </div>
                <div class="editor-field">
                    <%: Html.TextBoxFor(m => m.UserName) %>
                    <%: Html.ValidationMessageFor(m => m.UserName) %>
                </div>

                <div class="editor-label">
                    <%: Html.LabelFor(m => m.Password) %>
                </div>
                <div class="editor-field">
                    <%: Html.PasswordFor(m => m.Password) %>
                    <%: Html.ValidationMessageFor(m => m.Password) %>
                </div>

                <div class="editor-label">
                    <%: Html.CheckBoxFor(m => m.RememberMe) %>
                    <%: Html.LabelFor(m => m.RememberMe) %>
                </div>

                <p>
                    <input type="submit" value="Log On" />
                </p>
            </fieldset>
        </div>
    <% } %>
</asp:Content>

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
        Inherits="System.Web.Mvc.ViewPage<ITOC.WebUI.Models.UserExtended>" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        Create
    </asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Create</h2>
    <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>

        <fieldset>
            <legend>Fields</legend>

            <div class="editor-label">
                <%: Html.LabelFor(model => model.User.Forename) %>
            </div>
            <div class="editor-field">
                <%: Html.EditorFor(model => model.User.Forename)%>
                <%: Html.ValidationMessageFor(model => model.User.Forename)%>
            </div>

            <div class="editor-label">
                <%: Html.LabelFor(model => model.User.Surname) %>
            </div>
            <div class="editor-field">
                <%: Html.EditorFor(model => model.User.Surname)%>
                <%: Html.ValidationMessageFor(model => model.User.Surname)%>
            </div>

            <div class="editor-label">
                <%: Html.LabelFor(model => model.User.EmailAddress) %>
            </div>
            <div class="editor-field">
                <%: Html.EditorFor(model => model.User.EmailAddress)%>
                <%: Html.ValidationMessageFor(model => model.User.EmailAddress)%>
            </div>

            <div class="editor-label">
                <%: Html.LabelFor(model => model.Password) %>
            </div>
            <div class="editor-field">
                <%: Html.PasswordFor(model => model.Password)%>
                <%: Html.ValidationMessageFor(model => model.Password) %>
            </div>

            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>

    <% } %>

    <div>
        <%: Html.ActionLink("Back to List", "List") %>
    </div>

</asp:Content>

+1  A: 

This is probably due to a browser autocompletion feature. You could append the non standard autocomplete="off" to your input fields:

<%: Html.TextBoxFor(model => model.User.Forename, new { autocomplete = "off" }) %>
Darin Dimitrov
That is the correct answer. I was trying AutoCompleteType.Disabled which came up in intellisense but this did not work the way I wanted. I also started to notice references to the answer you gave. Confusingly they cast doubt on whether the solution works with EditorFor. The answer is that it does!
arame3333