Partial view doesn't call Http Post Method












0















So I created a partial log in in my homepage. The form gets rendered properly, however it doesn't call the http post action result whenever I submit the form. Please see the below code for reference.



HomePage:



<header class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">


<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a href="@Url.Action("HomePage", "Home")" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="@Url.Action("Branchlist", "Branch")" class="nav-link">BRANCH</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>
</div>
</header>


Log In Partial



@model BBLoyalty.Models.LoyaltyAccountModel

<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

@using (Html.BeginForm("LogInBox", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<div class="form-row align-items-center">

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user"></i> </div>
</div>
@Html.TextBoxFor(s => s.Username, new { @class = "form-control", placeholder = "Username", autofocus = "autofocus" })
</div>
</div>

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-lock"></i> </div>
</div>
@Html.PasswordFor(s => s.Password, new { @class = "form-control", placeholder = "Password" })
</div>
</div>

<div class="col-auto">
<button type="submit" class="btn btn-secondary mb-2">Log In</button>
</div>
</div>

}


HomeController.cs



    public ActionResult LogInBox()

{
return View();
}


[HttpPost]
public ActionResult LogInBox(LoyaltyAccountModel acn)
{
if (ModelState.IsValid)
{
LoyaltyAccount ua = bbdb.LoyaltyAccounts.FirstOrDefault(x => x.Username == acn.Username && x.IsActive == true);
if (ua != null)
{
string ep = eh.GetEncrypted(acn.Password, acn.Username);

if (ua.Password == ep && ua.Type != "") // Needs to Identify the type of Account(Client/Admin) Otherwise Cannot Login
{

Session["ActiveUser"] = ua.UserId;

if (ua.Type == "Admin" || ua.Type == "SuperUser")
{
return RedirectToAction("Index", "Maintenance");
}
else
{
return RedirectToAction("Index", "Profile");
}
}
else
{
ViewBag.Message = "Incorrect Password!";

return View();
}
}
else
{
ViewBag.Message = "Invalid Account!";

return View();
}
}
else
{
return View();
}
}


Upon submission, it doesn't call the ActionResult LogInBox(LoyaltyAccountModel acn)



Please Help. It always calls the first ActionResult, the one without the parameter.



enter image description here










share|improve this question

























  • How do you confirm that it is not submitting? Did you put a breakpoint in Action method and try to debug the code?

    – Chetan Ranpariya
    Nov 13 '18 at 11:33











  • You have nested <form> tags, one in Home and another in partial. Nested forms are not supported. You can have multiple forms in a single page, but not nested within each other.

    – Thangadurai
    Nov 13 '18 at 11:37











  • Yes I did, as I have stated the first ActionResult is always the one that gets called.

    – Elijah Elcano
    Nov 13 '18 at 11:44
















0















So I created a partial log in in my homepage. The form gets rendered properly, however it doesn't call the http post action result whenever I submit the form. Please see the below code for reference.



HomePage:



<header class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">


<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a href="@Url.Action("HomePage", "Home")" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="@Url.Action("Branchlist", "Branch")" class="nav-link">BRANCH</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>
</div>
</header>


Log In Partial



@model BBLoyalty.Models.LoyaltyAccountModel

<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

@using (Html.BeginForm("LogInBox", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<div class="form-row align-items-center">

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user"></i> </div>
</div>
@Html.TextBoxFor(s => s.Username, new { @class = "form-control", placeholder = "Username", autofocus = "autofocus" })
</div>
</div>

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-lock"></i> </div>
</div>
@Html.PasswordFor(s => s.Password, new { @class = "form-control", placeholder = "Password" })
</div>
</div>

<div class="col-auto">
<button type="submit" class="btn btn-secondary mb-2">Log In</button>
</div>
</div>

}


HomeController.cs



    public ActionResult LogInBox()

{
return View();
}


[HttpPost]
public ActionResult LogInBox(LoyaltyAccountModel acn)
{
if (ModelState.IsValid)
{
LoyaltyAccount ua = bbdb.LoyaltyAccounts.FirstOrDefault(x => x.Username == acn.Username && x.IsActive == true);
if (ua != null)
{
string ep = eh.GetEncrypted(acn.Password, acn.Username);

if (ua.Password == ep && ua.Type != "") // Needs to Identify the type of Account(Client/Admin) Otherwise Cannot Login
{

Session["ActiveUser"] = ua.UserId;

if (ua.Type == "Admin" || ua.Type == "SuperUser")
{
return RedirectToAction("Index", "Maintenance");
}
else
{
return RedirectToAction("Index", "Profile");
}
}
else
{
ViewBag.Message = "Incorrect Password!";

return View();
}
}
else
{
ViewBag.Message = "Invalid Account!";

return View();
}
}
else
{
return View();
}
}


Upon submission, it doesn't call the ActionResult LogInBox(LoyaltyAccountModel acn)



Please Help. It always calls the first ActionResult, the one without the parameter.



enter image description here










share|improve this question

























  • How do you confirm that it is not submitting? Did you put a breakpoint in Action method and try to debug the code?

    – Chetan Ranpariya
    Nov 13 '18 at 11:33











  • You have nested <form> tags, one in Home and another in partial. Nested forms are not supported. You can have multiple forms in a single page, but not nested within each other.

    – Thangadurai
    Nov 13 '18 at 11:37











  • Yes I did, as I have stated the first ActionResult is always the one that gets called.

    – Elijah Elcano
    Nov 13 '18 at 11:44














0












0








0








So I created a partial log in in my homepage. The form gets rendered properly, however it doesn't call the http post action result whenever I submit the form. Please see the below code for reference.



HomePage:



<header class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">


<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a href="@Url.Action("HomePage", "Home")" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="@Url.Action("Branchlist", "Branch")" class="nav-link">BRANCH</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>
</div>
</header>


Log In Partial



@model BBLoyalty.Models.LoyaltyAccountModel

<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

@using (Html.BeginForm("LogInBox", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<div class="form-row align-items-center">

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user"></i> </div>
</div>
@Html.TextBoxFor(s => s.Username, new { @class = "form-control", placeholder = "Username", autofocus = "autofocus" })
</div>
</div>

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-lock"></i> </div>
</div>
@Html.PasswordFor(s => s.Password, new { @class = "form-control", placeholder = "Password" })
</div>
</div>

<div class="col-auto">
<button type="submit" class="btn btn-secondary mb-2">Log In</button>
</div>
</div>

}


HomeController.cs



    public ActionResult LogInBox()

{
return View();
}


[HttpPost]
public ActionResult LogInBox(LoyaltyAccountModel acn)
{
if (ModelState.IsValid)
{
LoyaltyAccount ua = bbdb.LoyaltyAccounts.FirstOrDefault(x => x.Username == acn.Username && x.IsActive == true);
if (ua != null)
{
string ep = eh.GetEncrypted(acn.Password, acn.Username);

if (ua.Password == ep && ua.Type != "") // Needs to Identify the type of Account(Client/Admin) Otherwise Cannot Login
{

Session["ActiveUser"] = ua.UserId;

if (ua.Type == "Admin" || ua.Type == "SuperUser")
{
return RedirectToAction("Index", "Maintenance");
}
else
{
return RedirectToAction("Index", "Profile");
}
}
else
{
ViewBag.Message = "Incorrect Password!";

return View();
}
}
else
{
ViewBag.Message = "Invalid Account!";

return View();
}
}
else
{
return View();
}
}


Upon submission, it doesn't call the ActionResult LogInBox(LoyaltyAccountModel acn)



Please Help. It always calls the first ActionResult, the one without the parameter.



enter image description here










share|improve this question
















So I created a partial log in in my homepage. The form gets rendered properly, however it doesn't call the http post action result whenever I submit the form. Please see the below code for reference.



HomePage:



<header class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">


<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a href="@Url.Action("HomePage", "Home")" class="nav-link">HOME</a>
</li>
<li class="nav-item">
<a href="@Url.Action("Branchlist", "Branch")" class="nav-link">BRANCH</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>
</div>
</header>


Log In Partial



@model BBLoyalty.Models.LoyaltyAccountModel

<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

@using (Html.BeginForm("LogInBox", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<div class="form-row align-items-center">

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user"></i> </div>
</div>
@Html.TextBoxFor(s => s.Username, new { @class = "form-control", placeholder = "Username", autofocus = "autofocus" })
</div>
</div>

<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-lock"></i> </div>
</div>
@Html.PasswordFor(s => s.Password, new { @class = "form-control", placeholder = "Password" })
</div>
</div>

<div class="col-auto">
<button type="submit" class="btn btn-secondary mb-2">Log In</button>
</div>
</div>

}


HomeController.cs



    public ActionResult LogInBox()

{
return View();
}


[HttpPost]
public ActionResult LogInBox(LoyaltyAccountModel acn)
{
if (ModelState.IsValid)
{
LoyaltyAccount ua = bbdb.LoyaltyAccounts.FirstOrDefault(x => x.Username == acn.Username && x.IsActive == true);
if (ua != null)
{
string ep = eh.GetEncrypted(acn.Password, acn.Username);

if (ua.Password == ep && ua.Type != "") // Needs to Identify the type of Account(Client/Admin) Otherwise Cannot Login
{

Session["ActiveUser"] = ua.UserId;

if (ua.Type == "Admin" || ua.Type == "SuperUser")
{
return RedirectToAction("Index", "Maintenance");
}
else
{
return RedirectToAction("Index", "Profile");
}
}
else
{
ViewBag.Message = "Incorrect Password!";

return View();
}
}
else
{
ViewBag.Message = "Invalid Account!";

return View();
}
}
else
{
return View();
}
}


Upon submission, it doesn't call the ActionResult LogInBox(LoyaltyAccountModel acn)



Please Help. It always calls the first ActionResult, the one without the parameter.



enter image description here







c# razor model-view-controller partial-views






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 11:34







Elijah Elcano

















asked Nov 13 '18 at 11:28









Elijah ElcanoElijah Elcano

103




103













  • How do you confirm that it is not submitting? Did you put a breakpoint in Action method and try to debug the code?

    – Chetan Ranpariya
    Nov 13 '18 at 11:33











  • You have nested <form> tags, one in Home and another in partial. Nested forms are not supported. You can have multiple forms in a single page, but not nested within each other.

    – Thangadurai
    Nov 13 '18 at 11:37











  • Yes I did, as I have stated the first ActionResult is always the one that gets called.

    – Elijah Elcano
    Nov 13 '18 at 11:44



















  • How do you confirm that it is not submitting? Did you put a breakpoint in Action method and try to debug the code?

    – Chetan Ranpariya
    Nov 13 '18 at 11:33











  • You have nested <form> tags, one in Home and another in partial. Nested forms are not supported. You can have multiple forms in a single page, but not nested within each other.

    – Thangadurai
    Nov 13 '18 at 11:37











  • Yes I did, as I have stated the first ActionResult is always the one that gets called.

    – Elijah Elcano
    Nov 13 '18 at 11:44

















How do you confirm that it is not submitting? Did you put a breakpoint in Action method and try to debug the code?

– Chetan Ranpariya
Nov 13 '18 at 11:33





How do you confirm that it is not submitting? Did you put a breakpoint in Action method and try to debug the code?

– Chetan Ranpariya
Nov 13 '18 at 11:33













You have nested <form> tags, one in Home and another in partial. Nested forms are not supported. You can have multiple forms in a single page, but not nested within each other.

– Thangadurai
Nov 13 '18 at 11:37





You have nested <form> tags, one in Home and another in partial. Nested forms are not supported. You can have multiple forms in a single page, but not nested within each other.

– Thangadurai
Nov 13 '18 at 11:37













Yes I did, as I have stated the first ActionResult is always the one that gets called.

– Elijah Elcano
Nov 13 '18 at 11:44





Yes I did, as I have stated the first ActionResult is always the one that gets called.

– Elijah Elcano
Nov 13 '18 at 11:44












1 Answer
1






active

oldest

votes


















0














Since you have form tag in Home and another form tag in partial, this generates nested forms at runtime which is not supported.



Remove the form tag from the below code.



<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>





share|improve this answer
























  • You're a hero my friend. I didn't paid attention to that detail. I finally get it to work. I've been melding with this for a couple of hours.

    – Elijah Elcano
    Nov 13 '18 at 11:47











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280048%2fpartial-view-doesnt-call-http-post-method%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Since you have form tag in Home and another form tag in partial, this generates nested forms at runtime which is not supported.



Remove the form tag from the below code.



<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>





share|improve this answer
























  • You're a hero my friend. I didn't paid attention to that detail. I finally get it to work. I've been melding with this for a couple of hours.

    – Elijah Elcano
    Nov 13 '18 at 11:47
















0














Since you have form tag in Home and another form tag in partial, this generates nested forms at runtime which is not supported.



Remove the form tag from the below code.



<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>





share|improve this answer
























  • You're a hero my friend. I didn't paid attention to that detail. I finally get it to work. I've been melding with this for a couple of hours.

    – Elijah Elcano
    Nov 13 '18 at 11:47














0












0








0







Since you have form tag in Home and another form tag in partial, this generates nested forms at runtime which is not supported.



Remove the form tag from the below code.



<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>





share|improve this answer













Since you have form tag in Home and another form tag in partial, this generates nested forms at runtime which is not supported.



Remove the form tag from the below code.



<form class="form-inline my-2 my-lg-0">
<div> @{Html.RenderAction("LogInBox");}</div>>
</form>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 11:41









ThangaduraiThangadurai

1,1791123




1,1791123













  • You're a hero my friend. I didn't paid attention to that detail. I finally get it to work. I've been melding with this for a couple of hours.

    – Elijah Elcano
    Nov 13 '18 at 11:47



















  • You're a hero my friend. I didn't paid attention to that detail. I finally get it to work. I've been melding with this for a couple of hours.

    – Elijah Elcano
    Nov 13 '18 at 11:47

















You're a hero my friend. I didn't paid attention to that detail. I finally get it to work. I've been melding with this for a couple of hours.

– Elijah Elcano
Nov 13 '18 at 11:47





You're a hero my friend. I didn't paid attention to that detail. I finally get it to work. I've been melding with this for a couple of hours.

– Elijah Elcano
Nov 13 '18 at 11:47


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280048%2fpartial-view-doesnt-call-http-post-method%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine