Reputation: 4364
I have a partial view name test/index
following is the code -
@model MyFirstMVC.Models.testModels
@using (Html.BeginForm())
{
@Html.TextBox("test1")
<input type="submit" value="click" />
@ViewBag.a
}
And the controller of this partial view is following -
[HttpPost]
public ActionResult Index(MyFirstMVC.Models.testModels m)
{
ViewBag.a = Request["test1"].ToString() + " from controler";
return View(m);
}
In my parent view I am embedding my partial view like below -
@Html.Partial("../test/index",new MyFirstMVC.Models.testModels())
When I run the application, the partial view do appear in the parent view. But when I enter value inside partial view and submit then nothing is happening (the value is not forwarding to the controller of partial view - I have checked that the controller action method related to the partial view is not invoking either by setting break-point).
Any help will be appreciated. Why my partial view is not sending value to its controller?
Upvotes: 1
Views: 2980
Reputation:
You need to specify the controller and action names in Html.BeginForm()
if your not posting back to the same method that generated the view
@model MyFirstMVC.Models.testModels
@using (Html.BeginForm("Index", "Test"))
{
@Html.TextBox("test1")
<input type="submit" value="click" />
@ViewBag.a
}
Upvotes: 3