[ad_1]
My Submit Form Button Not Working ..
When I press on Login Button Nothing Happens ...
I can fix my problem with JQuery ajax codes but I don't want use JQuery Ajax for submitting Form ..I want to understand and resolve this MVC problem
thank you ...
User Model :
namespace Models
public class User : BaseEntity
public User() : base()
[System.ComponentModel.DataAnnotations.Required]
public string Username get; set;
[System.ComponentModel.DataAnnotations.Required]
[System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
public string Password get; set;
BaseEntity Class has only Id (System.Guid) Property
Controller :
public class AdminController : Infrastructure.BaseController
[System.Web.Mvc.HttpGet]
public System.Web.Mvc.ActionResult Index()
return View();
[System.Web.Mvc.HttpGet]
public System.Web.Mvc.ActionResult Login()
return View();
[System.Web.Mvc.HttpGet]
public System.Web.Mvc.ActionResult Edit()
return View();
[System.Web.Mvc.HttpPost]
[System.Web.Mvc.ValidateAntiForgeryToken]
public System.Web.Mvc.ActionResult Login([System.Web.Mvc.Bind(Include = "Id,Username,Password")] Models.User user)
string password = AAk.Security.Hashing.GetMD5(user.Password);
Models.User oUser = MyDatabaseContext.Users
.Where(current => current.Username.Contains(user.Username))
.Where(current => current.Password == password)
.FirstOrDefault();
if(oUser != null)
System.Web.Security.FormsAuthentication.SetAuthCookie(user.Username, false);
Session["AdminUserId"] = user.Id;
return (RedirectToAction("Edit", "Admin"));
else
//ModelState.AddModelError(string.Empty, "Login Failed!");
PageMessages.Add(new Infrastructure.PageMessage(Infrastructure.PageMessage.Types.Error, "Login Failed!"));
return (View(model: user));
Login.cshtml
@model Models.User
@
ViewBag.Title = "Login";
Layout = "~/Views/Shared/_Layout.cshtml";
<h2>Login</h2>
@using (Html.BeginForm("Login", "Admin", FormMethod.Post))
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.Partial(partialViewName: "~/Views/Shared/_PageMessages.cshtml")
@Html.ValidationSummary(true, "", new @class = "text-danger" )
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.Username, htmlAttributes: new @class = "control-label col-md-2" )
<div class="col-md-10">
@Html.EditorFor(model => model.Username, new htmlAttributes = new @class = "form-control", @id = "username" )
@Html.ValidationMessageFor(model => model.Username, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Password, htmlAttributes: new @class = "control-label col-md-2" )
<div class="col-md-10">
@Html.EditorFor(model => model.Password, new htmlAttributes = new @class = "form-control", @id = "password" )
@Html.ValidationMessageFor(model => model.Password, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Login" class="btn btn-default" id="login-button" />
</div>
</div>
</div>
<div>
@Html.ActionLink("Back to List", "Index")
</div>
[ad_2]
لینک منبع