Reputation: 2911
I'm new to Asp.Net MVC and I can't figure out how to update data on post for a Partial View. I don't have a problem with the GET and displaying the data in the partial view.
I'm not sure where to put the post code for the partial view data....in the post method for the parent page? or a post method for the partial view?
When I run the code below I get this message when I submit.
"A public action method 'ScoreRelease' was not found on controller 'Registration.Web.Controllers.AgreementsController'."}
It finds the controller on the initial page load, but not when I call return View("Review"); in the post method.
Parial View called from "Review" page
@{Html.RenderAction("ScoreRelease", "Agreements");}
ScoreRelease Partial View
@model Registration.Web.Models.ReviewModel.ReleaseScore
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<div class='group' id='data_release'>
<h4>
Data Release
</h4>
<p>
Do you wish to release your scores?
</p>
<ul class='input_group'>
<li>
@Html.RadioButtonFor(model => model.ReleaseScoreIndicator, true)
<label>
Yes
</label>
</li>
<li>
@Html.RadioButtonFor(model => model.ReleaseScoreIndicator, false)
<label>
No
</label>
</li>
</ul>
<input type="submit" value="Save" />
</div>
}
Review Controller
public ActionResult Review()
{
return View();
}
[HttpPost]
public ActionResult Review(ReviewModel.ReleaseScore model)
{
var agmtsService = new AgreementsService();
agmtsService.UpdateReleaseScoreIndicator(model.ReleaseScoreIndicator);
return View("Review");
}
[HttpGet]
public ActionResult ScoreRelease()
{
var agmtsService = new AgreementsService();
bool scoreRelease = agmtsService.GetReleaseScoreIndicator();
var vm = new ReviewModel.ReleaseScore();
vm.ReleaseScoreIndicator = scoreRelease;
return PartialView(vm);
}
Upvotes: 2
Views: 1487
Reputation: 228
You have to put Post Method in Partial View. You can do it two way either Html.BeginForm()
or Ajax.BeginForm
. If you are display this Partial View in Popup window then better use it as Ajax. Whatever Action you put in view you have to make same method name with [httppost]
tag in controller.
Upvotes: 0
Reputation: 11964
Use Html.BeginForm with parameters:
@using (Html.BeginForm("Action", "Controller", FormMethod.Post))
Upvotes: 1