blue
blue

Reputation: 588

I want to call HttpPost of Partial view on submit but it calls HttpPost of ParentView Always. Why?

I am using partial view inside a view (parent view)

I have a form in Partial view and when I click on submit button of partial view I want to call [HttpPost] method of partial view... but it doesn't get called it calls only the [HttpPost] of parent view...

[HttpPost]
        public ActionResult ParentView(Model model)
        {

            return View();
        }
[HttpPost]
        public ActionResult PartialView(Model model)
        {
            return View();
        }

Upvotes: 0

Views: 2753

Answers (2)

blue
blue

Reputation: 588

Got the solution... To add partial view to main view it needs to add using RenderAction()

Upvotes: 1

Chintana Meegamarachchi
Chintana Meegamarachchi

Reputation: 1820

Two solutions,

First: Pass controller and action name explicitly to BeginForm method

using (Html.BeginForm(“MyActionName”,”MyControllerName”, FormMethod.Post)) {

Second: use jquery to do the submit. For this, first setup an id on the form and call submit on it using a the click event of standard html input (type=button)

using (Html.BeginForm(null, null, FormMethod.Post, new { id = "partialViewForm"})) {

$(‘#partialViewForm’).submit()

Upvotes: 2

Related Questions