How to include the login form on the Home index page in MVC
- by Bernard Larouche
Hi guys
I really need your help for this. I am relatively new to programming and I need help to something that could be easy for a experienced programmer.
I would like to get the login form that we get for free in an MVC application on the left sidebar of my Home index page instead of the usual Account/Login page.
I am facing some problems.
First I need a product object to be displayed on my Home Index page as well.
What I did is that I added a product object to the LogOnModel that they provide in the AccountModels class and I created a UserControl (partial view) copying the content of the LogOn.aspx view. Now my Home index.aspx as well as my partial view inherits the LogOnModel class.
I can see the Login form on my Home Index page as well as my product object BUT the login Form is never empty. The last username and password always appear there.
I know I must have forgotten something or have done something wrong or the way did it is completely wrong !!
Please could you give me some advice
Thks
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CoderForTradersSite.Models.LogOnModel>" %>
<h4>Login Form</h4>
<p>
Please enter your username and password. <%= Html.ActionLink("Register", "Register") %> if you don't have an account.
</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>
<% } %>