我正在嘗試渲染包含簡單html表單的局部視圖。我想從控制器呈現表單,因爲我從重載的控制器方法處理回發。我曾嘗試@ Html.Action(「ContactForm」),但我得到一個異常,因爲子操作不能重定向。部分視圖和html格式Asp Mvc
我的控制器:
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);
}
我的表格:
@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" />
}
上我將如何做到這一點任何幫助,將不勝感激。