Wednesday, 14 August 2013

Forwarding the partial view's details to HttpPost method of a controller when button in partial view is clicked

Forwarding the partial view's details to HttpPost method of a controller
when button in partial view is clicked

Whenever following HttpGet method in controller is called it generates a
partial view.
Controller HttpGet Method
[HttpGet]
public ActionResult AddCredit(Guid creditBalanceId)
{
var newCredit = new AddCredits()
{
CreditBalanceId = creditBalanceId
};
return PartialView(newCredit);
}
View
@model AdminPortal.Areas.Customer.Models.ViewModels.AddCredits
@Html.HiddenFor(m=>m.CreditBalanceId)
<div class="input-small" id="credit">@Html.EditorFor(m=>m.CreditToAdd) </div>
@Html.ActionLink("Add","AddCredit", new {@class="btn"})
Whenever Add button is clicked in the partial view, I want it to be
forwarded to HttpPost method of my controller with
HiddenFor(CreditBalanceId) and CreditToAdd value
[HttpPost]
public ActionResult AddCredit(AddCredits credits)
{
_businessUnitRepository.AddCredits(credits);
Information("Credits Successfully added!");
return RedirectToAction("LicenseDetails");
}
Question
What changes do I need to make to my view so that when the button is
clicked, i get forwarded to httppost method in controller with all the
values?

No comments:

Post a Comment