Revathi
Revathi

Reputation: 1

Post is not working in MVC

   **View:**
   @model BusinessLayer.Family
   @{
     Layout = "~/Views/Shared/_Layout.cshtml";
    }
    @using (Html.BeginForm("FamilyDetails", "Family", FormMethod.Post))
    {
     <input id="btn_submit" type="submit" value="Submit" />
    }

    **controller:**
    [HttpGet]
    public ActionResult FamilyDetails()
    {
        Family mymodel = new Family();
        return View(mymodel);
    }

    [HttpPost]
    public string FamilyDetails()
    {
        return "Family";
    }

Without using Layout Post is Working.When i am using Layout,Get is firing instead of post.Please Help me.thank you

Upvotes: 0

Views: 65

Answers (2)

Akash Vashista
Akash Vashista

Reputation: 55

Please Specify Form Method in Begin form Area at least, because by default it calls Post Method.When you are using Layout Action is Partially rendered in the body of Layout so it hits the get area of Action. But when you are using without layout it is having a direct URL of an action and by default it is hitting to Post area of an action.

Upvotes: 1

PRABA
PRABA

Reputation: 460

try this.

    @using (Html.BeginForm("submit", "controllername",FormMethod.Post))
{ 
  <input id="btn_submit" type="submit" value="Submit" />
}

Upvotes: 0

Related Questions