Forums - C# Corner

Forum guidelines
Chandrakant Verma

Chandrakant Verma

  • 1.5k
  • 5
  • 315

pass ID in @html.actionlink

Apr 20 2017 1:35 AM
hi,
 
view: 
  1. @using (Html.BeginForm())  
  2. {  
  3.     @Html.ValidationSummary(true, "Login Failed, check details");  
  4.   
  5.     <div>  
  6.   
  7.         <br />  
  8.   
  9.         <fieldset>  
  10.             <legend>Login Form</legend>  
  11.             <div class="editor-label">@Html.LabelFor(u => u.UserName)</div>  
  12.             <div class="editor-field">  
  13.                 @Html.TextBoxFor(u => u.UserName)  
  14.                 @Html.ValidationMessageFor(u => u.UserName)  
  15.             </div>  
  16.             <div class="editor-label">@Html.LabelFor(u => u.Password)</div>  
  17.             <div class="editor-field">  
  18.                 @Html.PasswordFor(u => u.Password)  
  19.                 @Html.ValidationMessageFor(u => u.Password)  
  20.             </div>  
  21.             <br />  
  22.             <input type="submit" value="Log In" />  
  23.             <button class="btn btn-lg btn-success btn-block" type="submit">@Html.ActionLink("Login", "Login", "Home", new { /* ID TO BE PASSED*/ }, null)</button>  
  24.         </fieldset>  
  25.     </div>  
  26. }  
 controller: 
  1. public ActionResult Index()  
  2.       {  
  3.           return View();  
  4.       }  
  5.   
  6.       [ChildActionOnly]  
  7.       public ActionResult Login()  
  8.       {  
  9.           return PartialView("_Login");  
  10.       }  
  11.   
  12.       [HttpPost]  
  13.   
  14.       //[ValidateAntiForgeryToken]  
  15.       public ActionResult Login(Models.Account objUser)  
  16.       {  
  17.           if (ModelState.IsValid)  
  18.           {  
  19.               using (MyDatabaseEntities db = new MyDatabaseEntities())  
  20.               {  
  21.                   var obj = db.Accounts.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();  
  22.                   if (obj != null)  
  23.                   {  
  24.                       Session["UserName"] = obj.UserName.ToString();  
  25.                       Session["IsAdmin"] = obj.IsAdmin.ToString();  
  26.                       return RedirectToAction("Index""Account");  
  27.                   }  
  28.               }  
  29.           }  
  30.           //  return View("Dashboard/Index");  
  31.           return View(objUser);  
  32.   
  33.       }    
 i want login controller to be executed whn login is clicked. please suggest what id is to be passed from the view to execute  public ActionResult Login(Models.Account objUser) controller.
 

Answers (6)