1
所以我最近在.net MVC中启动项目,并且一直存在保留数据的问题。我在某处读到,为了做到这一点,你必须来回传递模型。我尝试过这样做,但它仍然遇到问题。在我的项目中,我现在有两个按钮,getData和getData2。我的视图打印他们的真/假值。当我按下它时,它会变成真,但如果我按另一个,它会变成真,但另一个变成假。如果我同时按下它们,我希望它们都保持真实。MVC在控制器和表单之间跳转时保留模型
控制器:
[HttpPost]
public ActionResult GetData(TestSite.Models.FarModels theFars)
{
theFars.HasData = true;
return RedirectToAction("FarCalc",theFars);
}
[HttpPost]
public ActionResult GetData2(TestSite.Models.FarModels theFars)
{
theFars.HasData2 = true;
return RedirectToAction("FarCalc", theFars);
}
[HttpGet]
public ActionResult FarCalc(TestSite.Models.FarModels theFars)
{
return View(theFars);
}
查看:
@using (Html.BeginForm("GetData", "Home", FormMethod.Post))
{
//@Html.TextBoxFor(model => model.FarValue)
<input type="submit" value="GetData" />
}
@using (Html.BeginForm("GetData2", "Home", FormMethod.Post))
{
//@Html.TextBoxFor(model => model.FarValue)
<input type="submit" value="GetData2" />
}
@Model.HasData
@Model.HasData2
感谢