I am attempting to render a partial view that contains a simple html form. I want to render the form from a controller as I handle the postback from an overloaded controller method. I have tried @Html.Action("ContactForm")but I get an Exception because child actions cannot redirect.
My Controller:
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult ContactForm()
{
return PartialView(new ContactForm());
}
[HttpPost]
public ActionResult ContactForm(ContactForm Contact)
{
return RedirectToAction("FormResults", new { ContactForm = Contact });
}
public ActionResult FormResults(ContactForm Contact)
{
return PartialView(Contact);
}
My Form:
@using(Html.BeginForm())
{
<h2>Contact Form</h2>
<div class="input-group">
<h4>@Html.LabelFor(m => m.FirstName, "First Name")</h4>
@Html.TextBoxFor(m => m.FirstName, new { @class = "form-control", @placeholder = "First Name" })
</div>
<div class="input-group">
<h4>@Html.LabelFor(m => m.LastName, "Last Name")</h4>
@Html.TextBoxFor(m => m.LastName, new { @class = "form-control", @placeholder = "Last Name" })
</div>
<div class="input-group">
<h4>@Html.LabelFor(m => m.Email, "Email")</h4>
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", @placeholder = "Email", @type = "text" })
</div>
<input type="submit" class="btn btn-info" value="Submit" />
}
Any Help on how I would accomplish this would be appreciated.