我有一个表单,它是布局页面中的局部视图。成功后我需要在第一个地方渲染另一个局部视图。
然而,局部视图在第一个局部视图内呈现。 (例如,如果用户在Mydomain / index中填写表单,则新的局部视图应显示在同一个URL中。现在它显示在/ controller / create中。
[ChildActionOnly]
public ActionResult Create()
{
ViewBag.SubjectId = new SelectList(db.subjects, "SubjectId", "Subjectname");
return PartialView();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "InfoId,FirstName,SureName,PhoneNumber,Address,Email,EnterdDate,IsActive,Tipol,SubjectId")] Info info)
{
info.EnterdDate = DateTime.Now;
info.IsActive = false;
if (ModelState.IsValid)
{
db.infos.Add(info);
db.SaveChanges();
TempData["thanks"] = info.FullName;
return PartialView("_bla");
}
ViewBag.SubjectId = new SelectList(db.subjects, "SubjectId", "Subjectname", info.SubjectId);
return View(info);
}
public PartialViewResult _bla()
{
var thanks = TempData["thanks"];
return PartialView();
}
答案 0 :(得分:1)
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "InfoId,FirstName,SureName,PhoneNumber,Address,Email,EnterdDate,IsActive,Tipol,SubjectId")] Info info)
{
info.EnterdDate = DateTime.Now;
info.IsActive = false;
if (ModelState.IsValid)
{
db.infos.Add(info);
db.SaveChanges();
TempData["thanks"] = info.FullName;
return RedirectToAction("Create");
}
ViewBag.SubjectId = new SelectList(db.subjects, "SubjectId", "Subjectname", info.SubjectId);
return View(info);
}
查看创建:
@if (TempData["thanks"] != null)
{
<div class="alert alert-success">
@TempData["thanks"]
</div>
}
// your form