Thank you all friends to put many comments for help me!!!!
But i founded that i need to use Jquery script to submit the form using $.ajax function to _Login action.Here is my change codes.
//_Layout.cshtml
@model CSS_Test.ViewModels.CommentViewModel
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.7.1.min.js"></script>
<script>
$(document).ready(function () {
$("#submit").click(function () {
$.ajax({
type: "Post",
url: "Account/_Login",
data: $("#all_form").serialize(),
error: function (xhr, status, error) {
alert("Error,Something went wrong");
},
success: function (data) {
if (data.Err_message != null)
$("#invalid_user").html(data.Err_message);
}
})
});
});
</script>
@using (Html.BeginForm(null,null,FormMethod.Post,new{id="all_form"}))
{
<div>
@{
if (@Session["UserName"] == null)
{
<div id="User">
@Html.TextBoxFor(m => this.Model.LogModel.UserName, new { @class = "UserName", placeholder = "UserName", autofocus = "autofocus", @Autocomplete = "off" })
</div>
<br />
@Html.ValidationMessageFor(m => this.Model.LogModel.UserName)
<br />
@Html.PasswordFor(m => this.Model.LogModel.Password, new { @class = "Password", placeholder = "Password" })
<br />
@Html.ValidationMessageFor(m => this.Model.LogModel.Password)
<br />
<div style="color:#f00;font-weight:bold" id="invalid_user">
</div>
}
if (@Session["UserName"] != null)
{
<div style="color:#4cff00;font-weight:bold;direction:rtl">
@Session["UserName"] WelCome<br />
<div>@Html.ActionLink("LogOut", "LogOff", "Account")</div>
</div>
if (Request.UrlReferrer != null)
{
if (@Request.Url.AbsoluteUri.ToString().Contains("Account"))
{
<div style="padding-top:7px; ">
<a href="@Url.Action(" put_comment=", " admin=", new { UserName = @Session[" username="] })">Administrator Part</a>
</div>
}
}
}
if (@Session["UserName"] == null)
{
<br />
@Html.CheckBoxFor(m => this.Model.LogModel.RememberMe)
@Html.LabelFor(m => this.Model.LogModel.RememberMe)
<br />
<input type="button" value="submit" id="submit"/>
}
}
</div>
}
//my _Login action
[HttpPost]
public ActionResult _LogIn(CSS_Test.ViewModels.CommentViewModel model, string returnUrl)
{
Json_Res result = new Json_Res();
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.LogModel.UserName, model.LogModel.Password))
{
FormsAuthentication.SetAuthCookie(model.LogModel.UserName, model.LogModel.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
@Session["UserName"] = model.LogModel.UserName;
result.Comment_VM = model;
}
result.Err_message = "Invalid UserName Or Password";
}
return Json(result,JsonRequestBehavior.AllowGet);
}
// And this is Json_Res class Viewmodel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CSS_Test.Models;
namespace CSS_Test.ViewModels
{
public class Json_Res
{
public string Err_message { get; set; }
public CommentViewModel Comment_VM { get; set; }
}
}