TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chandrakant Verma
NA
33
13k
pass ID in @html.actionlink
Apr 20 2017 1:35 AM
hi,
view:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true, "Login Failed, check details");
<
div
>
<
br
/>
<
fieldset
>
<
legend
>
Login Form
</
legend
>
<
div
class
=
"editor-label"
>
@Html.LabelFor(
u
=
>
u.UserName)
</
div
>
<
div
class
=
"editor-field"
>
@Html.TextBoxFor(
u
=
>
u.UserName)
@Html.ValidationMessageFor(
u
=
>
u.UserName)
</
div
>
<
div
class
=
"editor-label"
>
@Html.LabelFor(
u
=
>
u.Password)
</
div
>
<
div
class
=
"editor-field"
>
@Html.PasswordFor(
u
=
>
u.Password)
@Html.ValidationMessageFor(
u
=
>
u.Password)
</
div
>
<
br
/>
<
input
type
=
"submit"
value
=
"Log In"
/>
<
button
class
=
"btn btn-lg btn-success btn-block"
type
=
"submit"
>
@Html.ActionLink("Login", "Login", "Home", new { /* ID TO BE PASSED*/ }, null)
</
button
>
</
fieldset
>
</
div
>
}
controller:
public
ActionResult Index()
{
return
View();
}
[ChildActionOnly]
public
ActionResult Login()
{
return
PartialView(
"_Login"
);
}
[HttpPost]
//[ValidateAntiForgeryToken]
public
ActionResult Login(Models.Account objUser)
{
if
(ModelState.IsValid)
{
using
(MyDatabaseEntities db =
new
MyDatabaseEntities())
{
var obj = db.Accounts.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();
if
(obj !=
null
)
{
Session[
"UserName"
] = obj.UserName.ToString();
Session[
"IsAdmin"
] = obj.IsAdmin.ToString();
return
RedirectToAction(
"Index"
,
"Account"
);
}
}
}
// return View("Dashboard/Index");
return
View(objUser);
}
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.
Reply
Answers (
6
)
Add special character between single quotes
Prevent from duplicate insertion on save button