(MVC)如何RedirectToAction并在MVC4中保留Html.Textbox的内容?这是我的控制器如何修复它以及视图中的内容?
[HttpPost]
public ActionResult Index(string ssn)
{
var exist = false;
var record = _db.Citations.Where(u => u.SSN == ssn).FirstOrDefault();
if (record != null)
{
exist = true;
return RedirectToAction("EditDetails", new { id = record.CitationID });
}
else
{
return RedirectToAction("Index", "SubmitAward", ssn); // wiped out ssn! I need to keep the ssn
// so that the user can fill out the form.
}
答案 0 :(得分:0)
如果你的行动是这样的:
public ActionResult Index(string ssn)
{
.........
..........
.........
}
然后这样做:
return RedirectToAction("Index", "SubmitAward", new { ssn = ssn});
但是如果它与发布的帖子操作的索引视图相同,那么如果您的视图是强类型的,则可以将对象传回视图:
return View(record);
答案 1 :(得分:0)
尝试以下代码
return RedirectToAction("Index", "SubmitAward", new { ssn = ssn});
您的重定向操作将是
public ActionResult Index(string ssn)
{
ViewBag.SSN=ssn;
return View(record);
}
您的视图将包含类似
的文本框@Html.TextBox("SSN",ViewBag.SSN)
它可以帮助你......